This is a .NET library that allows you to invoke an external process and expose its output as an async stream in C# 8.0.
using Toolbelt.Diagnostics;
...
using var process = await XProcess.Start("foo.exe").WaitForExitAsync();
if (process.ExitCode != 0) throw new Exception(process.Output);
using Toolbelt.Diagnostics;
...
using var process = XProcess.Start("foo.exe");
await foreach(string output in process.GetOutputAsyncStream())
{
// do something.
}
// When reaching here, it means the process was exited.
using Toolbelt.Diagnostics;
...
using var process = XProcess.Start("foo.exe");
var found = await process.WaitForOutputAsync(str => str.Contains("Now listening on:"), option => {
option.IdleTimeout = 1000;
option.ProcessTimeout = 5000;
});
// When the "found" is false, it means the process
// has not outputted "Now listening on:" in 5 seconds
// or has not output any response over 1 second.
using Toolbelt.Diagnostics;
...
await XProcess.Start("foo.exe", options => {
options.EnvironmentVariables["FOO"] = "BAR";
}).WaitForExitAsync();
Release notes are here.