Class ProcessLauncher
Runs a child process.
public class ProcessLauncher : IProcessLauncher
- Inheritance
-
ProcessLauncher
- Implements
- Extension Methods
Constructors
ProcessLauncher(ProcessStartInfo)
Creates a new process launcher.
public ProcessLauncher(ProcessStartInfo startInfo)
Parameters
startInfo
ProcessStartInfo
ProcessLauncher(string, string?)
Runs a child process.
public ProcessLauncher(string fileName, string? arguments = null)
Parameters
fileName
stringThe file name of the executable to run.
arguments
stringThe default arguments to always pass to the executable.
Fields
Arguments
protected readonly string? Arguments
Field Value
FileName
protected readonly string FileName
Field Value
Methods
GetStartInfo(params string[])
Creates the ProcessStartInfo used to launch the process.
public virtual ProcessStartInfo GetStartInfo(params string[] arguments)
Parameters
arguments
string[]The arguments to pass to the process at startup.
Returns
HandleExitCode(Process, string?)
Hook for handling exit codes.
protected virtual void HandleExitCode(Process process, string? message = null)
Parameters
Exceptions
- ExitCodeException
ExitCode had a non-zero value.
OnStderr(string, StreamWriter)
Hook for handling stderr messages from the process.
protected virtual void OnStderr(string line, StreamWriter stdin)
Parameters
line
stringThe line written to stderr.
stdin
StreamWriterThe stream writer providing access to stdin.
Run(params string[])
Runs the process and waits for it to exit.
public virtual void Run(params string[] arguments)
Parameters
arguments
string[]Command-line arguments to launch the process with.
Exceptions
- IOException
There was a problem launching the executable.
- FileNotFoundException
The executable file could not be found.
- NotAdminException
The target process requires elevation.
- ExitCodeException
The process exited with a non-zero ExitCode.
RunAndCapture(Action<StreamWriter>?, params string[])
Runs the process, captures its stdout and stderr output and waits for it to exit.
public virtual string RunAndCapture(Action<StreamWriter>? onStartup, params string[] arguments)
Parameters
onStartup
Action<StreamWriter>A callback for writing to the process' stdin right after startup.
arguments
string[]Command-line arguments to launch the process with.
Returns
- string
The process' complete stdout output.
Exceptions
- IOException
There was a problem launching the executable.
- FileNotFoundException
The executable file could not be found.
- NotAdminException
The target process requires elevation.
- ExitCodeException
The process exited with a non-zero ExitCode.
Start(params string[])
Starts the process and runs it in parallel with this one.
public Process Start(params string[] arguments)
Parameters
arguments
string[]Command-line arguments to launch the process with.
Returns
- Process
The newly launched process.
Exceptions
- IOException
There was a problem launching the executable.
- FileNotFoundException
The executable file could not be found.
- NotAdminException
The target process requires elevation.