Show / Hide Table of Contents

Class ProcessLauncher

Runs a child process.

Inheritance
Object
ProcessLauncher
Implements
IProcessLauncher
Namespace: NanoByte.Common.Native
Assembly: NanoByte.Common.dll
Syntax
public class ProcessLauncher : Object, IProcessLauncher

Constructors

ProcessLauncher(ProcessStartInfo)

Creates a new process launcher.

Declaration
public ProcessLauncher(ProcessStartInfo startInfo)
Parameters
Type Name Description
ProcessStartInfo startInfo

Extracts FileName and Arguments. Other options are ignored.

ProcessLauncher(String, String)

Creates a new process launcher.

Declaration
public ProcessLauncher(string fileName, string arguments = null)
Parameters
Type Name Description
String fileName

The file name of the executable to run.

String arguments

The default arguments to always pass to the executable.

Fields

Arguments

Declaration
protected readonly string Arguments
Field Value
Type Description
String

FileName

Declaration
protected readonly string FileName
Field Value
Type Description
String

Methods

GetStartInfo(String[])

Creates the ProcessStartInfo used to launch the process.

Declaration
public virtual ProcessStartInfo GetStartInfo(params string[] arguments)
Parameters
Type Name Description
String[] arguments

The arguments to pass to the process at startup.

Returns
Type Description
ProcessStartInfo

HandleExitCode(Process, String)

Hook for handling exit codes.

Declaration
protected virtual void HandleExitCode(Process process, string message = null)
Parameters
Type Name Description
Process process

The process that has exited.

String message

An optional error message.

Exceptions
Type Condition
ExitCodeException

ExitCode had a non-zero value.

OnStderr(String, StreamWriter)

Hook for handling stderr messages from the process.

Declaration
protected virtual void OnStderr(string line, StreamWriter stdin)
Parameters
Type Name Description
String line

The line written to stderr.

StreamWriter stdin

The stream writer providing access to stdin.

Run(String[])

Runs the process and waits for it to exit.

Declaration
public virtual void Run(params string[] arguments)
Parameters
Type Name Description
String[] arguments

Command-line arguments to launch the process with.

Exceptions
Type Condition
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>, String[])

Runs the process, captures its stdout and stderr output and waits for it to exit.

Declaration
public virtual string RunAndCapture(Action<StreamWriter> onStartup, params string[] arguments)
Parameters
Type Name Description
Action<StreamWriter> onStartup

A callback for writing to the process' stdin right after startup.

String[] arguments

Command-line arguments to launch the process with.

Returns
Type Description
String

The process' complete stdout output.

Exceptions
Type Condition
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(String[])

Starts the process and runs it in parallel with this one.

Declaration
public Process Start(params string[] arguments)
Parameters
Type Name Description
String[] arguments

Command-line arguments to launch the process with.

Returns
Type Description
Process

The newly launched process.

Exceptions
Type Condition
IOException

There was a problem launching the executable.

FileNotFoundException

The executable file could not be found.

NotAdminException

The target process requires elevation.

Implements

IProcessLauncher

Extension Methods

UpdateUtils.To<TIn, TOut>(TIn, Func<TIn, TOut>)
JsonStorage.SaveJson<T>(T, Stream)
JsonStorage.SaveJson<T>(T, String)
JsonStorage.ToJsonString<T>(T)
JsonStorage.ReparseAsJson<T>(Object)
JsonStorage.ReparseAsJson<T>(Object, T)
XmlStorage.SaveXml(Object, Stream, String)
XmlStorage.SaveXml<T>(T, String, String)
XmlStorage.ToXmlString(Object, String)
ConversionUtils.ConvertToString<TType>(TType)
In This Article
Back to top Copyright Bastian Eicher