-
-
Save ivanxpetrov/88f126b411bc608703f907516059b27d to your computer and use it in GitHub Desktop.
C# Process wrapper
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; | |
| using System.Linq; | |
| static class Program { | |
| static int Main(string[] args) { | |
| var p = new ProcessStartInfo { | |
| FileName = args[0], | |
| // TODO: quote args | |
| Arguments = String.Join(" ", args.Skip(1).ToArray()), | |
| RedirectStandardInput = true, | |
| RedirectStandardError = true, | |
| RedirectStandardOutput = true, | |
| UseShellExecute = false | |
| }; | |
| var process = Process.Start(p); | |
| process.BeginOutputReadLine(); | |
| process.OutputDataReceived += (s, e) => Console.Out.WriteLine(e.Data); | |
| process.BeginErrorReadLine(); | |
| process.OutputDataReceived += (s, e) => Console.Error.WriteLine(e.Data); | |
| string l; | |
| while ((l = Console.ReadLine()) != null) { | |
| process.StandardInput.WriteLine(l); | |
| process.StandardInput.Flush(); | |
| } | |
| process.StandardInput.Close(); | |
| process.WaitForExit(); | |
| return process.ExitCode; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment