I have WinForm application which allow to run different scripts. most scripts invoke gmake.exe. I want to display output of the script's run in one of my windows.
After i redirecting all necessary streams and set all necessary attributes i get everything working except one case: when gmake.exe shows error. It is usually happening when it has a dependency which should be built. gmake.exe first checking for the file, does not find it and prints out to stderr something like:
stb.mak:125: myfile.rd: No such file or directory
and then it continues by creating it (according to some rule) and so on...
However, in my output i get:
stb.mak:125: myfile.rd: No such file or directory
process_easy: DuplicateHandle(In) failed (e=6)
"gmake": Interrupt/Exception caught (code = 0xc0000005, addr = 0x412fd4)
and process ends.
If i do not redirect output then everything works fine until the end but i do not see progress.
The same (working fine until the end) goes when no errors are displayed by gmake.exe during the script's execution.
My code that starts process is below:
buildProc = new Process(); buildProc.StartInfo.FileName = "gmake"; buildProc.StartInfo.Arguments = "-r -f makefile.mak"; buildProc.StartInfo.RedirectStandardOutput = true; buildProc.StartInfo.RedirectStandardError = true; buildProc.StartInfo.UseShellExecute = false; buildProc.StartInfo.CreateNoWindow = true; buildProc.OutputDataReceived += new DataReceivedEventHandler(OutputHandler); buildProc.ErrorDataReceived += new DataReceivedEventHandler(OutputHandler); buildProc.Exited += new EventHandler(ExitedHandler); buildProc.EnableRaisingEvents = true; buildProc.Start(); buildProc.BeginOutputReadLine(); buildProc.BeginErrorReadLine(); |
What should i do to avoid it. Note that .NET Visual Studio handles this situation

Processing gmake.exe in separate process
Bugzzbunny
My problem is that gmake generates some errors but continue to run. It look like the process treats these errors like exception. Another reason that your version is wrong is the fact that using only one stream redirection (either stdout or stderr) produce the same result. Only in the case i redirect stdout i do not see those lines.
Please, anybody who used to run gmake.exe with scripts that create dependency files and solved the problem, Help!
My time is running out and i am stacked with this stupid behavior.
Chuck C
The solution as recommended by Microsoft is contained in the documentation for ProcessStartInfo.RedirectStandardOutput and involves either creating a separate thread for each stream and then forcefully terminating the threads when the process ends or using an asychronous read operation. The asychronous read operation was added in 2.0 and is the best route.
Michael Taylor - 10/2/05