Summary
Starts the process resource that is specified by the filename and settings.
Syntax
[CakeMethodAlias]
public static int StartProcess(this ICakeContext context, FilePath fileName, ProcessSettings settings, out IEnumerable<string> redirectedStandardOutput, out IEnumerable<string> redirectedErrorOutput)
Examples
IEnumerable<string> redirectedStandardOutput;
IEnumerable<string> redirectedErrorOutput;
var exitCodeWithArgument =
StartProcess(
"ping",
new ProcessSettings {
Arguments = "localhost",
RedirectStandardOutput = true,
RedirectStandardError = true
},
out redirectedStandardOutput,
out redirectedErrorOutput
);
// Output last line of process output.
Information("Last line of output: {0}", redirectedStandardOutput.LastOrDefault());
// Throw exception if anything was written to the standard error.
if (redirectedErrorOutput.Any())
{
throw new Exception(
string.Format(
"Errors occurred: {0}",
string.Join(", ", redirectedErrorOutput)));
}
// This should output 0 as valid arguments supplied
Information("Exit code: {0}", exitCodeWithArgument);
Attributes
Parameters
Name |
Type |
Description |
context |
ICakeContext |
The context. |
fileName |
FilePath |
Name of the file. |
settings |
ProcessSettings |
The settings. |
redirectedStandardOutput |
IEnumerable<string> |
Returns process output if RedirectStandardOutput is true.
Otherwise null is returned. |
redirectedErrorOutput |
IEnumerable<string> |
Returns process error output if RedirectStandardError is true.
Otherwise null is returned. |
Return Value
Type |
Description |
int |
The exit code that the started process specified when it terminated. |