Last active
February 1, 2017 13:51
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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