ProcessRunOptions Class
Holds the options of a run of IProcessRunner.RunAsync.
This type is not available in the netstandard and .NET Framework builds of Louis, as ProcessRunner is not.
public sealed class ProcessRunOptionsRemarks
A run has one of two modes, which ProcessRunOptions.InheritStandardStreams selects.
In capture mode, the default, the runner redirects the standard streams of the child: it writes the standard input of the child, and reads its standard output and its standard error.
In inherited mode, the child shares the standard streams of the current process, and the runner reads nothing.
Constructors
| Name | Description |
|---|---|
| ProcessRunOptions() |
ProcessRunOptions()
Available in: net10.0net11.0(not available in the other target frameworks of the package)
public ProcessRunOptions()No documentation is available.
Properties
| Name | Description |
|---|---|
| Environment | Gets the changes to make to the environment of the child. |
| InheritStandardStreams | Gets a value indicating whether the child shares the standard streams of the current process. |
| OnStandardErrorLine | Gets the callback that receives each line the child writes to its standard error. |
| OnStandardOutputLine | Gets the callback that receives each line the child writes to its standard output. |
| OutputEncoding | Gets the encoding of the text that the child writes to its standard output and to its standard error. |
| StandardInput | Gets the stream that holds the data for the standard input of the child. |
| ThrowOnNonZeroExitCode | Gets a value indicating whether an exit code other than 0 throws a ProcessFailedException. |
| WorkingDirectory | Gets the working directory of the child. |
Environment
Available in: net10.0net11.0(not available in the other target frameworks of the package)
Gets the changes to make to the environment of the child.
public IReadOnlyDictionary<string, string?>? Environment { get; init; }Property value
IReadOnlyDictionary<string, string?>? A dictionary of environment variables, or null for no change. The default is null.
Remarks
The child starts with the environment of the current process. A variable with a non-null value is added to it, or replaces the variable of the same name. A variable with a null value is removed from it.
InheritStandardStreams
Available in: net10.0net11.0(not available in the other target frameworks of the package)
Gets a value indicating whether the child shares the standard streams of the current process.
public bool InheritStandardStreams { get; init; }Property value
bool true for inherited mode: the child shares the standard streams of the current process. false for capture mode: the runner redirects the standard streams of the child, and reads what the child writes. The default is false.
Remarks
When this property is true, the runner ignores ProcessRunOptions.StandardInput, ProcessRunOptions.OutputEncoding, ProcessRunOptions.OnStandardOutputLine, and ProcessRunOptions.OnStandardErrorLine, and both texts of the ProcessResult are empty.
OnStandardErrorLine
Available in: net10.0net11.0(not available in the other target frameworks of the package)
Gets the callback that receives each line the child writes to its standard error.
Property value
Action<string>? A callback, or null for none. The default is null.
Remarks
The runner calls the callback once per line, as the line arrives, with the text of the line without its terminator.
The runner calls the callback from a thread of the thread pool. It never calls the same callback twice at the same time, but it may call this callback and ProcessRunOptions.OnStandardOutputLine at the same time.
The runner never calls the callback after IProcessRunner.RunAsync has returned its result or thrown. When the run is canceled, or fails, while the callback is running, IProcessRunner.RunAsync throws after the callback returns.
When the callback throws an exception, the runner kills the child, and IProcessRunner.RunAsync throws the same exception.
The runner ignores this property when ProcessRunOptions.InheritStandardStreams is true.
OnStandardOutputLine
Available in: net10.0net11.0(not available in the other target frameworks of the package)
Gets the callback that receives each line the child writes to its standard output.
Property value
Action<string>? A callback, or null for none. The default is null.
Remarks
The runner calls the callback once per line, as the line arrives, with the text of the line without its terminator.
The runner calls the callback from a thread of the thread pool. It never calls the same callback twice at the same time, but it may call this callback and ProcessRunOptions.OnStandardErrorLine at the same time.
The runner never calls the callback after IProcessRunner.RunAsync has returned its result or thrown. When the run is canceled, or fails, while the callback is running, IProcessRunner.RunAsync throws after the callback returns.
When the callback throws an exception, the runner kills the child, and IProcessRunner.RunAsync throws the same exception.
The runner ignores this property when ProcessRunOptions.InheritStandardStreams is true.
OutputEncoding
Available in: net10.0net11.0(not available in the other target frameworks of the package)
Gets the encoding of the text that the child writes to its standard output and to its standard error.
public Encoding? OutputEncoding { get; init; }Property value
Encoding? An encoding, or null to use ConsoleUtility.SystemDefaultEncoding. The default is null.
Remarks
The runner cannot know the encoding a child writes with. A console program that sets no encoding writes with the encoding of its console. For a child whose output the runner reads, that encoding is ConsoleUtility.SystemDefaultEncoding. Set this property for a child that writes with another encoding.
The runner ignores this property when ProcessRunOptions.InheritStandardStreams is true.
StandardInput
Available in: net10.0net11.0(not available in the other target frameworks of the package)
Gets the stream that holds the data for the standard input of the child.
public Stream? StandardInput { get; init; }Property value
Stream? A readable stream, or null for no data. The default is null.
Remarks
The runner copies the stream to the standard input of the child, from the current position of the stream to its end, then closes the standard input of the child. The runner does not dispose the stream. With null, the child finds its standard input at its end.
The runner ignores this property when ProcessRunOptions.InheritStandardStreams is true.
ThrowOnNonZeroExitCode
Available in: net10.0net11.0(not available in the other target frameworks of the package)
Gets a value indicating whether an exit code other than 0 throws a ProcessFailedException.
public bool ThrowOnNonZeroExitCode { get; init; }Property value
bool true to throw a ProcessFailedException when the child exits with a code other than 0; false to return the ProcessResult whatever the exit code. The default is true.
WorkingDirectory
Available in: net10.0net11.0(not available in the other target frameworks of the package)