[Mono-devel-list] Capturing Shell Output: System.Diagnostics.Process

Jörg Rosenkranz joergr at voelcker.com
Wed Feb 2 09:49:40 EST 2005


Hello Ben,

> -----Original Message-----
> From: mono-devel-list-admin at lists.ximian.com 
> 
> I'm using the code:
> 
> Process proc = new Process();
> proc.EnableRaisingEvents=false;
> proc.StartInfo.FileName= "command";
> proc.StartInfo.Arguments = "--args";
> proc.Start();
> proc.WaitForExit();
> 
> ...to execute a shell command. I can get the proc.ExitCode to get the
> status of the execution, but I'd like to be able to capture 
> the std out
> messages too, and the error messages from this command. Is there a way
> of doing this? I've Googled for a bit, but not found much.
> 

proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;

...

string stdOut = proc.StandardOutput.ReadToEnd();
string stdErr = proc.StandardError.ReadToEnd();

HTH,
Joerg.



More information about the Mono-devel-list mailing list