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)

Prepares a new sub process.

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

The file name of the executable to run and default arguments to always pass. Other information from the ProcessStartInfo is ignored!

ProcessLauncher(String, String)

Prepares a new sub process.

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.

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

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 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 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.

WaitForExit(Process)

Hook for waiting for a process to exit and handle its exit code.

Declaration
protected virtual void WaitForExit(Process process)
Parameters
Type Name Description
Process process

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