Introduction
editMeziantou.Framework.ProcessWrapper runs processes. You describe the command with a fluent API, start it, and await the result. The package takes care of the parts that are easy to get wrong with System.Diagnostics.Process: reading standard output and standard error at the same time without deadlocking, decoding them line by line, passing arguments without quoting them, killing the process when the operation is canceled, and checking the exit code.
What you can do with it
- Run a command and wait for it, with its arguments, working directory and environment variables. See Getting started and Configuring the process.
- Read the output line by line, into a collection, a
StringBuilder, aTextWriteror a stream, or capture all of it. See Reading the output. - Write to the standard input, and connect processes with a pipe or the
|operator. See Input and pipes. - Validate the result: throw on a non-zero exit code or on output on standard error. See Exit codes and errors.
- Cancel or kill a running process. See Cancellation and killing.
- Limit CPU, memory and the number of processes with Windows Job Objects or Linux control groups. See Resource limits.
- Replace processes in tests with fake processes, and change commands globally with interceptors. See Testing.
- Trace executions with
System.Diagnosticsactivities. See Telemetry.
Namespace
The types are in the Meziantou.Framework namespace. The main ones:
| Type | Contains |
|---|---|
| ProcessWrapper | The command to run, its configuration, and the methods that start it |
| ProcessInstance, BufferedProcessInstance | A running process, to await or kill |
| ProcessResult, BufferedProcessResult | The exit code and dates of a process that exited, and its output when buffered |
| ProcessExitCode | An exit code |
| OutputTarget, InputSource | Where the output goes, and where the input comes from |
| ProcessOutputCollection, ProcessOutput | Captured output lines |
| ProcessPipe, ProcessPipeline | Connections between processes |
| ProcessLimits | The CPU, memory and process count limits |
| FakeProcess, FakeProcessFactory | In-memory processes for tests |
Next steps
- Getting started: install the package and run your first command.