Tuesday, 9 June 2009

C# Open process and capture standard output

[Test]
public void TestStartProcess()
{
System.Diagnostics.Process process = new System.Diagnostics.Process();

process.StartInfo.FileName = "echo";
//Open as readonly
process.StartInfo.Arguments = "Hello World!";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.WorkingDirectory = @"c:\temp";

process.Start();

StreamReader reader = process.StandardOutput;
string output = reader.ReadToEnd();

Console.WriteLine(output);

}

No comments:

Post a Comment