[Mono-list] Redirecting stderr to stdout

Colin JN Breame colin at talkingpixels.co.uk
Tue Feb 7 07:58:53 EST 2006


Consider:

	Process p = new Process();
	p.StartInfo.FileName = "gmcs";
	p.StartInfo.Arguments = "file1.cs file2.cs";
	p.StartInfo.UseShellExecute = false;
        p.StartInfo.RedirectStandardOutput = true;
	p.StartInfo.RedirectStandardError = true;
        p.Start();
        string output = p.StandardOutput.ReadToEnd();
	output += p.StandardError.ReadToEnd();
	Console.WriteLine(output);

The problem with this is that the order of the actual output will be lost.  
Theoretically (correct me if I'm wrong) this could also cause a deadlock:

 - p.StandardOutput.ReadToEnd() blocks until StandardOutput is closed.
 - the process never closes StandardOutput as it is blocked writing to 
StandardError (not entirely sure that this can happen - output buffers 
exceeded?).

So, is there a mono way of redirecting stderr to stdout without having to 
write a shell script wrapper?  Adding 2>&1 to StartInfo.Arguments doesn't 
have any effect.

Cheers,

 -- Colin


More information about the Mono-list mailing list