Skip to content

Instantly share code, notes, and snippets.

@atifaziz
Created March 26, 2019 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atifaziz/3d7fe8501441aa645df5ca1ba2f96ec8 to your computer and use it in GitHub Desktop.
Save atifaziz/3d7fe8501441aa645df5ca1ba2f96ec8 to your computer and use it in GitHub Desktop.
Demo program for discussion of dotnet/cli#11016
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
</Project>
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