Created
March 26, 2019 06:59
-
-
Save atifaziz/3d7fe8501441aa645df5ca1ba2f96ec8 to your computer and use it in GitHub Desktop.
Demo program for discussion of dotnet/cli#11016
This file contains 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
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<TargetFramework>netcoreapp2.1</TargetFramework> | |
</PropertyGroup> | |
</Project> |
This file contains 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.Collections; | |
using System.Diagnostics; | |
using System.Linq; | |
static class Program | |
{ | |
static int Main(string[] args) | |
{ | |
var psi = new ProcessStartInfo(args[0]) | |
{ | |
UseShellExecute = false, | |
CreateNoWindow = true, | |
RedirectStandardOutput = true, | |
RedirectStandardError = true, | |
}; | |
foreach (var arg in args.Skip(1)) | |
psi.ArgumentList.Add(arg); | |
using (var process = Process.Start(psi)) | |
{ | |
process.OutputDataReceived += (_, ea) => | |
{ | |
if (ea.Data != null) | |
Console.WriteLine(ea.Data); | |
}; | |
process.ErrorDataReceived += (_, ea) => | |
{ | |
if (ea.Data != null) | |
Console.Error.WriteLine(ea.Data); | |
}; | |
process.BeginOutputReadLine(); | |
process.BeginErrorReadLine(); | |
process.WaitForExit(); | |
return process.ExitCode; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment