0

The code below fails to timeout. I'd like to read the output of the process even if I have to close it.

var proc = new Process
{
 StartInfo = new ProcessStartInfo
{
 FileName = '"' + filepath + '"',
Arguments = execArgs,
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
}
};

proc.Start();
string poutput = proc.StandardOutput.ReadToEnd();
bool bl = proc.WaitForExit(0 * 60 * 1000);

1 Answers1

1

You can use OutputDataReceived event

StringBuilder sb = new StringBuilder();
proc.OutputDataReceived += (x,s) => sb.AppendLine(s.Data);

proc.Start();
proc.BeginOutputReadLine();

proc.WaitForExit(0 * 60 * 1000);
var output = sb.ToString();
Eser
  • 12,346
  • 1
  • 22
  • 32