var process = Process.Start(
new ProcessStartInfo("ping", "google.com") {
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
RedirectStandardInput = true });
Console.WriteLine(process.StandardOutput.ReadToEnd());
Notes:
UseShellExecute must be false, otherwise reading from StandardOutput throws an exception.RedirectStandardInput may be needed even if you don’t need to redirect input stream.References: