Class ProcessLauncher
Runs a child process.
public class ProcessLauncher : IProcessLauncher
- Inheritance
-
objectProcessLauncher
- Implements
- Extension Methods
Constructors
ProcessLauncher(ProcessStartInfo)
Creates a new process launcher.
public ProcessLauncher(ProcessStartInfo startInfo)
Parameters
startInfo
ProcessStartInfoExtracts System.Diagnostics.ProcessStartInfo.FileName and System.Diagnostics.ProcessStartInfo.Arguments. Other options are ignored.
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
- string
FileName
protected readonly string FileName
Field Value
- string
Methods
GetStartInfo(params string[])
Creates the System.Diagnostics.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
- ProcessStartInfo
HandleExitCode(Process, string?)
Hook for handling exit codes.
protected virtual void HandleExitCode(Process process, string? message = null)
Parameters
process
ProcessThe process that has exited.
message
stringAn optional error message.
Exceptions
- ExitCodeException
System.Diagnostics.Process.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 System.Diagnostics.Process.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 System.Diagnostics.Process.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.