I want to start a powershell script from c# dotnet core, I am using psexe and process.start but I am able to see a process ID, but how do I print what that process is doing, for example if I try to run a powershell script, how do I print output of the script executed by the powershell.
You are probably looking how to redirect the standard output of the process.
You can redirect standard output (enable it in the process start options) and read from it.
Incomplete Code:
This sample prints the whole stdout after the program has finished. You can adapt it to print text while the code is running. 😊
You can’t access out-of-process memory or results or anything really. Your best bet is accessing a shared disk resource like a file or database. Welcome to distributed systems design.
You may want to look at a callback or event driven system if this script is supposed to execute/interact with something that the originating process can’t. That is: at end of script send event/mesaage to originating process event listener/POST endpoint. Turning the originating process into a “fire & forget”. You’ll have to make some governing saga orchestrator to make sure all expected events/messages are received.
Thank you for replying,
>> Your best bet is accessing a shared disk resource like a file or database ?
I like this idea.
>> That is: at end of script send event/message to originating process event listener/POST endpoint.
I really like this idea too, but I want to keep it something simple as am not using any API’s or DB. in this case what would be the best way to even/message origination process that you suggest?
C# devs
null reference exceptions