Introduction

edit

Meziantou.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, a TextWriter or 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.Diagnostics activities. See Telemetry.

Namespace

The types are in the Meziantou.Framework namespace. The main ones:

TypeContains
ProcessWrapperThe command to run, its configuration, and the methods that start it
ProcessInstance, BufferedProcessInstanceA running process, to await or kill
ProcessResult, BufferedProcessResultThe exit code and dates of a process that exited, and its output when buffered
ProcessExitCodeAn exit code
OutputTarget, InputSourceWhere the output goes, and where the input comes from
ProcessOutputCollection, ProcessOutputCaptured output lines
ProcessPipe, ProcessPipelineConnections between processes
ProcessLimitsThe CPU, memory and process count limits
FakeProcess, FakeProcessFactoryIn-memory processes for tests

Next steps