RedirectStandardOutput in Process class is not working until the process is killed  
Author Message
Chandu Sujay





PostPosted: .NET Base Class Library, RedirectStandardOutput in Process class is not working until the process is killed Top


ProcessStartInfo psInfo = new ProcessStartInfo(instlLocation, "connect " + sStoreName);
psInfo.RedirectStandardInput = true;
psInfo.RedirectStandardOutput = true;
psInfo.UseShellExecute = false;
psInfo.CreateNoWindow = true;

Process process = new Process();
process.StartInfo = psInfo;
process.Start();

vin = process.StandardOutput;

I am not able to get the output stream with the above code using vin.Read(), until the process is terminated or I kill the process using below code. Any right help will be greatly appreciated.

process.WaitForExit(10000);

if (process.HasExited == false)
{
process.Kill();
process.Close();
}

process.Dispose();



.NET Development34  
 
 
nobugz





PostPosted: .NET Base Class Library, RedirectStandardOutput in Process class is not working until the process is killed Top

The Read doesn't complete until the app's console output buffer is filled to capacity or until it is closed. You can get a "live feed" from the buffer by implementing the OutputDataReceived event handler. The MSDN library article for that event has a good example on how to use it. Beware that the event fires on a non-GUI thread so you'll need to use Control.Invoke to display the output on your form...


 
 
Chandu Sujay





PostPosted: .NET Base Class Library, RedirectStandardOutput in Process class is not working until the process is killed Top

Is it possible to set OutbufferSize so that I will get data Synchronously, instead of changing my whole design to Asynchronous way.
 
 
nobugz





PostPosted: .NET Base Class Library, RedirectStandardOutput in Process class is not working until the process is killed Top

The output buffer is created by the app that you call, not by your program. Async is the only way afaik.