Skip to content

Instantly share code, notes, and snippets.

@atifaziz atifaziz/Demo.csproj
Created Mar 26, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.