Skip to content

Instantly share code, notes, and snippets.

@SteGriff
Last active February 1, 2017 13:51
Show Gist options
  • Select an option

  • Save SteGriff/54ae36485f8a15af63b27859d40de166 to your computer and use it in GitHub Desktop.

Select an option

Save SteGriff/54ae36485f8a15af63b27859d40de166 to your computer and use it in GitHub Desktop.
A tiny C# class to start a process and return its stdout text
using System;
using System.Diagnostics;
namespace SteGriff.Utilities
{
public class ProcessReader
{
public static string StartProcessAndGetOutput(string filename, string args = "")
{
ProcessStartInfo startInfo = new ProcessStartInfo()
{
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardInput = true,
UseShellExecute = false,
Arguments = args,
FileName = filename
};
Process p = new Process();
p.StartInfo = startInfo;
p.Start();
p.WaitForExit();
return p.StandardOutput.ReadToEnd();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment