CommandAliases.

Command(ICakeContext, ICollection<string>, string, string, ProcessArgumentBuilder, int, Func<CommandSettings, CommandSettings>) Method

Summary

Executes a generic tool/process based on arguments, settings, redirects standard output and standard error.
Namespace
Cake.Common.Tools.Command
Containing Type
CommandAliases

Syntax

[CakeMethodAlias]
[CakeAliasCategory("Command")]
public static int Command(this ICakeContext context, ICollection<string> toolExecutableNames, out string standardOutput, out string standardError, ProcessArgumentBuilder arguments = null, int expectedExitCode = 0, Func<CommandSettings, CommandSettings> settingsCustomization = null)

Examples

 // Example with ProcessArgumentBuilder
 var exitCode = Command(
     new []{ "dotnet", "dotnet.exe" },
     out var standardOutput,
     out var standardError,
     new ProcessArgumentBuilder()
         .Append("tool"),
     expectedExitCode:1
 );

 Verbose("Exit code: {0}", exitCode);
 Information("Output: {0}", standardOutput);
 Error("Error: {0}", standardError);


 // Example with implicit ProcessArgumentBuilder
 var implicitExitCode = Command(
     new []{ "dotnet", "dotnet.exe" },
     out var implicitStandardOutput,
     out var implicitStandardError,
     "tool",
     expectedExitCode:1
 );

 Verbose("Exit code: {0}", implicitExitCode);
 Information("Output: {0}", implicitStandardOutput);
 Error("Error: {0}", implicitStandardError);


 // Example settings customization
 var settingsCustomizationExitCode = Command(
     new []{ "dotnet", "dotnet.exe" },
     out var settingsCustomizationStandardOutput,
     out var settingsCustomizationStandardError,
     settingsCustomization: settings => settings
                                         .WithToolName(".NET Tool")
                                         .WithArgumentCustomization(args => args.Append("tool"))
                                         .WithExpectedExitCode(1)
 );

 Verbose("Exit code: {0}", settingsCustomizationExitCode);
 Information("Output: {0}", settingsCustomizationStandardOutput);
 Error("Error: {0}", settingsCustomizationStandardError);

Attributes

Type Description
CakeMethodAliasAttribute An attribute used to mark script method aliases.
CakeAliasCategoryAttribute An attribute used for documentation of alias methods/properties.

Parameters

Name Type Description
context ICakeContext The context.
toolExecutableNames ICollection<string> The tool executable names.
standardOutput string The standard output.
standardError string The standard error.
arguments ProcessArgumentBuilder The optional arguments.
expectedExitCode int The expected exit code (default 0).
settingsCustomization Func<CommandSettings, CommandSettings> The optional settings customization (default null).

Return Value

Type Description
int The exit code.