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);

}

Comments

Popular posts from this blog

Parse XML to dynamic object in C#

C# Updating GUI from different thread