PeanutButter
Loading...
Searching...
No Matches
PeanutButter.Utils.ProcessIO Class Reference

More...

Inheritance diagram for PeanutButter.Utils.ProcessIO:
PeanutButter.Utils.IProcessIO PeanutButter.Utils.ProcessIO.UnstartedProcessIO

Classes

class  UnstartedProcessIO
 Represents an unstarted process-io instance. More...

Public Member Functions

 ProcessIO (string filename, params string[] arguments)
 Run the provided command, pipe output as it streams.
int WaitForExit ()
 Wait for the process to exit and return the exit code.
Returns

int? WaitForExit (int timeoutMs)
 Wait up to the timeout for the process to exit and return the exit code, if available.
Parameters
timeoutMilliseconds
Returns

void Kill ()
 Kill the underlying process.
bool WaitForOutput (StandardIo io, Func< string, bool > matcher)
 Waits for some output to be emitted from the process.
Parameters
io
matcher

bool WaitForOutput (StandardIo io, Func< string, bool > matcher, int timeoutMilliseconds)
 Waits for some output to be emitted from the process.
Parameters
io
matcher
timeoutMilliseconds

void Dispose ()
 Kills the process if it hasn't finished yet.

Static Public Member Functions

static UnstartedProcessIO In (string workingDirectory)
 Sets up ProcessIO to run within the provided folder. Usage: using var io = ProcessIO.In("/path/to/folder").Start("cmd", "arg1", "arg2")
static IProcessIO Start (string filename, params string[] args)
 Starts a ProcessIO instance for the given filename and args in the current working directory.
static IProcessIO Start (OutputModes outputMode, IEnumerable< Action< string > > stdoutReceiver, IEnumerable< Action< string > > stderrReceiver, string filename, params string[] args)
 Starts a ProcessIO instance for the given filename and args in the current working directory.
static string QuoteIfNecessary (string str)
 Quotes a string if it's necessary:
static IUnstartedProcessIO WithEnvironmentVariable (string name, string value)
 Sets up for the new process to use the provided environment variable.
static IUnstartedProcessIO WithEnvironment (IDictionary< string, string > environment)
 Sets up a bunch of environment variables for the new process.
static IUnstartedProcessIO WithStdOutReceiver (Action< string > receiver)
 Start the process with the eventing output mode, specifying a stdout receiver.
static IUnstartedProcessIO WithPassthroughIo ()
static IUnstartedProcessIO WithStdErrReceiver (Action< string > receiver)
 Start the process with the eventing output mode, specifying a stderr receiver.

Properties

string Filename [get]
 The program started by this ProcessIO.
string[] Arguments [get]
 A copy of the commandline arguments to that program.
string WorkingDirectory [get]
 The working directory in which the process was launched.
int MaxBufferLines = int.MaxValue [get, set]
 IO is buffered internally so you can start listening to it whenever you want, from the start - however, when the target process produces a lot of IO (eg mysqldump), it's reasonable to enforce a history limit to reduce memory usage.
string Commandline [get]
 Renders the commandline used to start this process.
int ProcessId [get]
 The process id.
bool Started [get]
 True if the process started properly.
Exception StartException [get]
 Set if the process didn't start properly, to the exception thrown.
Process Process [get]
 Access to the underlying Process.
OutputModes OutputMode [get]
 Which output mode to use (buffered collections or events). Note that changes to this property will not be observed after the process has started.
int ExitCode [get]
 Provides access to the exit code of the process, waiting for it to complete if necessary.
IEnumerable< string > StandardOutput [get]
 Read lines from stdout until the process exits.
IEnumerable< string > StandardOutputSnapshot [get]
 Read the lines captured thus far from stdout - does not wait for the process to complete.
IEnumerable< string > StandardError [get]
 Read lines from stderr until the process exits.
IEnumerable< string > StandardErrorSnapshot [get]
 Read the lines captured thus far from stderr - does not wait for the process to complete.
IEnumerable< string > StandardOutputAndErrorInterleaved [get]
 Read the lines from stderr and stdout (until the process exits), interleaved (mostly in order, though some minor out-of-order situations can occur between stderr and stdout if there is rapid output on both because of the async io handlers for dotnet Process objects.
IEnumerable< string > StandardOutputAndErrorInterleavedSnapshot [get]
 Read the lines captured thus far from stderr and stdout, interleaved (mostly in order, though some minor out-of-order situations can occur between stderr and stdout if there is rapid output on both because of the async io handlers for dotnet Process objects.
  • does not wait for the process to complete

StreamWriter StandardInput [get]
 Direct access to the StandardInput on the process.
bool HasExited [get]
 Flag: true when the process has exited (or couldn't start up)

Events

EventHandler< string > OnStdOut
EventHandler< string > OnStdErr
Events inherited from PeanutButter.Utils.IProcessIO
EventHandler< string > OnStdOut
 Raised when receiving data on stdout from the process.
EventHandler< string > OnStdErr
 Raised when receiving data on stderr from the process.

Detailed Description

Constructor & Destructor Documentation

◆ ProcessIO()

PeanutButter.Utils.ProcessIO.ProcessIO ( string filename,
params string[] arguments )

Run the provided command, pipe output as it streams.

Parameters
filenameapp to run
argumentsargs for that app

Member Function Documentation

◆ Dispose()

void PeanutButter.Utils.ProcessIO.Dispose ( )

Kills the process if it hasn't finished yet.

  • you should always dispose, since you may decide not to read until the process is dead

◆ In()

UnstartedProcessIO PeanutButter.Utils.ProcessIO.In ( string workingDirectory)
static

Sets up ProcessIO to run within the provided folder. Usage: using var io = ProcessIO.In("/path/to/folder").Start("cmd", "arg1", "arg2")

Parameters
workingDirectory
Returns

◆ Kill()

void PeanutButter.Utils.ProcessIO.Kill ( )

Kill the underlying process.

Implements PeanutButter.Utils.IProcessIO.

◆ QuoteIfNecessary()

string PeanutButter.Utils.ProcessIO.QuoteIfNecessary ( string str)
static

Quotes a string if it's necessary:

  • contains whitespace
Parameters
str
Returns

◆ Start() [1/2]

IProcessIO PeanutButter.Utils.ProcessIO.Start ( OutputModes outputMode,
IEnumerable< Action< string > > stdoutReceiver,
IEnumerable< Action< string > > stderrReceiver,
string filename,
params string[] args )
static

Starts a ProcessIO instance for the given filename and args in the current working directory.

Parameters
outputMode
stderrReceiver
filename
args
stdoutReceiver
Returns

◆ Start() [2/2]

IProcessIO PeanutButter.Utils.ProcessIO.Start ( string filename,
params string[] args )
static

Starts a ProcessIO instance for the given filename and args in the current working directory.

Parameters
filename
args
Returns

◆ WaitForExit() [1/2]

int PeanutButter.Utils.ProcessIO.WaitForExit ( )

Wait for the process to exit and return the exit code.

Returns

Implements PeanutButter.Utils.IProcessIO.

◆ WaitForExit() [2/2]

int? PeanutButter.Utils.ProcessIO.WaitForExit ( int timeoutMs)

Wait up to the timeout for the process to exit and return the exit code, if available.

Parameters
timeoutMilliseconds
Returns

Implements PeanutButter.Utils.IProcessIO.

◆ WaitForOutput() [1/2]

bool PeanutButter.Utils.ProcessIO.WaitForOutput ( StandardIo io,
Func< string, bool > matcher )

Waits for some output to be emitted from the process.

Parameters
io
matcher

Implements PeanutButter.Utils.IProcessIO.

◆ WaitForOutput() [2/2]

bool PeanutButter.Utils.ProcessIO.WaitForOutput ( StandardIo io,
Func< string, bool > matcher,
int timeoutMilliseconds )

Waits for some output to be emitted from the process.

Parameters
io
matcher
timeoutMilliseconds

Implements PeanutButter.Utils.IProcessIO.

◆ WithEnvironment()

IUnstartedProcessIO PeanutButter.Utils.ProcessIO.WithEnvironment ( IDictionary< string, string > environment)
static

Sets up a bunch of environment variables for the new process.

Parameters
environment
Returns

◆ WithEnvironmentVariable()

IUnstartedProcessIO PeanutButter.Utils.ProcessIO.WithEnvironmentVariable ( string name,
string value )
static

Sets up for the new process to use the provided environment variable.

Parameters
name
value
Returns

◆ WithPassthroughIo()

IUnstartedProcessIO PeanutButter.Utils.ProcessIO.WithPassthroughIo ( )
static
Returns

◆ WithStdErrReceiver()

IUnstartedProcessIO PeanutButter.Utils.ProcessIO.WithStdErrReceiver ( Action< string > receiver)
static

Start the process with the eventing output mode, specifying a stderr receiver.

Parameters
receiver
Returns

◆ WithStdOutReceiver()

IUnstartedProcessIO PeanutButter.Utils.ProcessIO.WithStdOutReceiver ( Action< string > receiver)
static

Start the process with the eventing output mode, specifying a stdout receiver.

Parameters
receiver
Returns

Property Documentation

◆ Arguments

string [] PeanutButter.Utils.ProcessIO.Arguments
get

A copy of the commandline arguments to that program.

Implements PeanutButter.Utils.IProcessIO.

◆ Commandline

string PeanutButter.Utils.ProcessIO.Commandline
get

Renders the commandline used to start this process.

Implements PeanutButter.Utils.IProcessIO.

◆ ExitCode

int PeanutButter.Utils.ProcessIO.ExitCode
get

Provides access to the exit code of the process, waiting for it to complete if necessary.

Implements PeanutButter.Utils.IProcessIO.

◆ Filename

string PeanutButter.Utils.ProcessIO.Filename
get

The program started by this ProcessIO.

Implements PeanutButter.Utils.IProcessIO.

◆ HasExited

bool PeanutButter.Utils.ProcessIO.HasExited
get

Flag: true when the process has exited (or couldn't start up)

Implements PeanutButter.Utils.IProcessIO.

◆ MaxBufferLines

int PeanutButter.Utils.ProcessIO.MaxBufferLines = int.MaxValue
getset

IO is buffered internally so you can start listening to it whenever you want, from the start - however, when the target process produces a lot of IO (eg mysqldump), it's reasonable to enforce a history limit to reduce memory usage.

Implements PeanutButter.Utils.IProcessIO.

◆ OutputMode

OutputModes PeanutButter.Utils.ProcessIO.OutputMode
get

Which output mode to use (buffered collections or events). Note that changes to this property will not be observed after the process has started.

Implements PeanutButter.Utils.IProcessIO.

◆ Process

Process PeanutButter.Utils.ProcessIO.Process
get

Access to the underlying Process.

Implements PeanutButter.Utils.IProcessIO.

◆ ProcessId

int PeanutButter.Utils.ProcessIO.ProcessId
get

The process id.

Implements PeanutButter.Utils.IProcessIO.

◆ StandardError

IEnumerable<string> PeanutButter.Utils.ProcessIO.StandardError
get

Read lines from stderr until the process exits.

Implements PeanutButter.Utils.IProcessIO.

◆ StandardErrorSnapshot

IEnumerable<string> PeanutButter.Utils.ProcessIO.StandardErrorSnapshot
get

Read the lines captured thus far from stderr - does not wait for the process to complete.

Implements PeanutButter.Utils.IProcessIO.

◆ StandardInput

StreamWriter PeanutButter.Utils.ProcessIO.StandardInput
get

Direct access to the StandardInput on the process.

Implements PeanutButter.Utils.IProcessIO.

◆ StandardOutput

IEnumerable<string> PeanutButter.Utils.ProcessIO.StandardOutput
get

Read lines from stdout until the process exits.

Implements PeanutButter.Utils.IProcessIO.

◆ StandardOutputAndErrorInterleaved

IEnumerable<string> PeanutButter.Utils.ProcessIO.StandardOutputAndErrorInterleaved
get

Read the lines from stderr and stdout (until the process exits), interleaved (mostly in order, though some minor out-of-order situations can occur between stderr and stdout if there is rapid output on both because of the async io handlers for dotnet Process objects.

Implements PeanutButter.Utils.IProcessIO.

◆ StandardOutputAndErrorInterleavedSnapshot

IEnumerable<string> PeanutButter.Utils.ProcessIO.StandardOutputAndErrorInterleavedSnapshot
get

Read the lines captured thus far from stderr and stdout, interleaved (mostly in order, though some minor out-of-order situations can occur between stderr and stdout if there is rapid output on both because of the async io handlers for dotnet Process objects.

  • does not wait for the process to complete

Implements PeanutButter.Utils.IProcessIO.

◆ StandardOutputSnapshot

IEnumerable<string> PeanutButter.Utils.ProcessIO.StandardOutputSnapshot
get

Read the lines captured thus far from stdout - does not wait for the process to complete.

Implements PeanutButter.Utils.IProcessIO.

◆ Started

bool PeanutButter.Utils.ProcessIO.Started
get

True if the process started properly.

Implements PeanutButter.Utils.IProcessIO.

◆ StartException

Exception PeanutButter.Utils.ProcessIO.StartException
get

Set if the process didn't start properly, to the exception thrown.

Implements PeanutButter.Utils.IProcessIO.

◆ WorkingDirectory

string PeanutButter.Utils.ProcessIO.WorkingDirectory
get

The working directory in which the process was launched.

Implements PeanutButter.Utils.IProcessIO.


The documentation for this class was generated from the following file:
  • source/Utils/PeanutButter.Utils/ProcessIO.cs