OutputDataReceived from Process Waits until the end

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
All,<br/> <br/> Ive got an exe that Im trying to run silently from within my application.  If I execute the binary in a command prompt (outside of my app), it spits out about 50 different lines as it is pushing some data over a serial connection before it finally exits.<br/> <br/> See the following code to see how I have it setup:<br/> <br/>
<pre lang="x-c# public static void DoTheButton()
{
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(
@"STMFlashLoader.exe", "-c --pn 8 --br 115200 -i STM32F10xxBxx -e --all -d --fn Sniper.s19");
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
psi.RedirectStandardInput = true;
psi.ErrorDialog = false;
psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
psi.CreateNoWindow = true;
psi.UseShellExecute = false;
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo = psi;

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

proc.OutputDataReceived += new System.Diagnostics.DataReceivedEventHandler(proc_OutputDataReceived);
}

static void proc_OutputDataReceived(object sender, System.Diagnostics.DataReceivedEventArgs e)
{
Console.WriteLine(e.Data);
}[/code]
<br/> <br/> I would expect that "proc_OutputDataReceived" gets called for each line that I normally see gets written out to the standard out when executing this binary from the command prompt.  <br/> <br/> Instead, when I kick off this method, I get nothing in console for about 10 seconds, then every one of those 50 lines comes through all at once, rapid fire at the end. <br/> <br/> Its like the OutputDataReceived doesnt actually get fired when the output lines are being generated, but only when the entire process finishes, then it gets called 50 times in row.<br/> <br/> Anybody have any experience with this?<br/> <br/> Id like to actually use OutputDataReceived to increment a progress bar for the background process.  <br/>

View the full article
 
Back
Top