Reputation: 6518
I'm wanting to capture a processes standard out stream after it has already been started.
ie. something like this pseudo code:
var process = Process.GetProcessById(1234);
process.OutputDataReceived += process_OutputDataReceived;
process.ErrorDataReceived += process_ErrorDataReceived;
process.Exited += process_Exited;
process.EnableRaisingEvents = true;
process.BeginErrorReadLine();
process.BeginOutputReadLine();
Id love a solution that doesn't force me to create pipes or call native code if possible etc.
Upvotes: 1
Views: 1134
Reputation: 13888
What about
process.StandardOutput.ReadToEnd();
Also process.BeginOutputReadLine();
may be of use.
Ofcourse this is assuming the original process was started with UseShellExecute = false
and RedirectStandardOutput = true
EDIT
As the process was possibly started using the shell and without redirection of stdout. Have a look at http://pastebin.com/f3eda7c8
Upvotes: 1