S
Steve
I have created a console app that simply prints out a message a couple
times, then exits, here is the code:
<code>
for(int i = 0; i < 10; i++)
{
System.Threading.Thread.Sleep(500);
Console.WriteLine(String.Format("Sleeping...{0}", i));
}
Console.WriteLine("Done!");
</code>
Then in my winform app, I have this bit of code that creates a new Process;
<code>
public void Build()
{
String commandLine = "";
commandLine =
@"C:\PMDRepository\Tools\DQ_Tools\FirmwareEditor\ConsoleTest\bin\Debug\Conso
leTest.exe";
// execute
Process process = new Process();
process.EnableRaisingEvents = true;
process.StartInfo.UseShellExecute = false;
process.Exited += new EventHandler(ProcessExited);
process.StartInfo.FileName = commandLine;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardOutput= true;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
try
{
process.Start();
m_working = true;
string line = string.Empty;
string previousReadLine = string.Empty;
while(process.StandardOutput.Peek() > -1)
{
line = process.StandardOutput.ReadLine();
if(line != previousReadLine)
{
previousReadLine = line;
m_log.LogRaw("IARBuilder:\t{0}", line);
}
}
}
catch(Exception ex)
{
m_log.LogError(ex.Message);
}
}
</code>
in the while(process.StandardOutput.Peek() > -1)) loop, execution enters
that once, but never again. I'm not sure what's happening, but it seems
like it captures the output once, then doesn't try to read it again. Anyone
know the correct way to do this?
Thanks for any help,
Steve
times, then exits, here is the code:
<code>
for(int i = 0; i < 10; i++)
{
System.Threading.Thread.Sleep(500);
Console.WriteLine(String.Format("Sleeping...{0}", i));
}
Console.WriteLine("Done!");
</code>
Then in my winform app, I have this bit of code that creates a new Process;
<code>
public void Build()
{
String commandLine = "";
commandLine =
@"C:\PMDRepository\Tools\DQ_Tools\FirmwareEditor\ConsoleTest\bin\Debug\Conso
leTest.exe";
// execute
Process process = new Process();
process.EnableRaisingEvents = true;
process.StartInfo.UseShellExecute = false;
process.Exited += new EventHandler(ProcessExited);
process.StartInfo.FileName = commandLine;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardOutput= true;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
try
{
process.Start();
m_working = true;
string line = string.Empty;
string previousReadLine = string.Empty;
while(process.StandardOutput.Peek() > -1)
{
line = process.StandardOutput.ReadLine();
if(line != previousReadLine)
{
previousReadLine = line;
m_log.LogRaw("IARBuilder:\t{0}", line);
}
}
}
catch(Exception ex)
{
m_log.LogError(ex.Message);
}
}
</code>
in the while(process.StandardOutput.Peek() > -1)) loop, execution enters
that once, but never again. I'm not sure what's happening, but it seems
like it captures the output once, then doesn't try to read it again. Anyone
know the correct way to do this?
Thanks for any help,
Steve