Visit https://github.com/asmichi/ChildProcess for the current development. This repository has been archived as a reference for a ProcessPipeline implementation.
A .NET library that provides functionality for creating child processes. Easier, less error-prone, more flexible than System.Diagnostics.Process
at creating child processes.
This library can be obtained via NuGet.
- Concentrates on creating a child process and obtaining its output.
- Cannot query status of a process.
- More destinations of redirection:
- NUL
- File (optionally appended)
- Pipe
- Handle
- Less error-prone default values for redirection:
- stdin to NUL
- stdout to the current stdout
- stderr to the current stderr
- Pipes are asynchronous; asynchronous reads and writes will be handled by IO completion ports.
WaitForExitAsync
.
Frameworks:
net471
or laternetcoreapp2.1
or later- (Will support frameworks that implement
netstandard2.1
)
Runtimes:
win10-x86
or later (Desktop)win10-x64
or later (Desktop)
linux-x64
support is planned but not implemented.
- When overriding environment variables, it is recommended that you include basic environment variables such as
SystemRoot
, etc.
See ProcessPipeline.Example (not yet) for more examples.
var si = new ChildProcessStartInfo("cmd", "/C", "echo", "foo")
{
StdOutputRedirection = OutputRedirection.OutputPipe,
};
using (var p = ChildProcess.Start(si))
{
using (var sr = new StreamReader(p.StandardOutput))
{
// "foo"
Console.Write(await sr.ReadToEndAsync());
}
await p.WaitForExitAsync();
// ExitCode: 0
Console.WriteLine("ExitCode: {0}", p.ExitCode);
}
var si = new ChildProcessStartInfo("cmd", "/C", "set")
{
StdOutputRedirection = OutputRedirection.File,
StdOutputFile = "env.txt"
};
using (var p = ChildProcess.Start(si))
{
await p.WaitForExitAsync();
}
// ALLUSERSPROFILE=C:\ProgramData
// ...
Console.WriteLine(File.ReadAllText("env.txt"));