< Back
Exec
Post
NAME Exec
SYNOPSIS
Helper function for executing command-line programs.
SYNTAX
Exec [-cmd] <ScriptBlock> [[-errorMessage] <String>] [[-maxRetries] <Int32>] [[-retryTriggerErrorPattern]
<String>] [[-workingDirectory] <String>] [<CommonParameters>]
DESCRIPTION
This is a helper function that runs a scriptblock and checks the PS variable $lastexitcode to see if an error
occcured.
If an error is detected then an exception is thrown.
This function allows you to run command-line programs without having to explicitly check fthe $lastexitcode
variable.
PARAMETERS
-cmd <ScriptBlock>
The scriptblock to execute. This scriptblock will typically contain the command-line invocation.
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-errorMessage <String>
The error message to display if the external command returned a non-zero exit code.
Required? false
Position? 2
Default value ($msgs.error_bad_command -f $cmd)
Accept pipeline input? false
Accept wildcard characters? false
-maxRetries <Int32>
The maximum number of times to retry the command before failing.
Required? false
Position? 3
Default value 0
Accept pipeline input? false
Accept wildcard characters? false
-retryTriggerErrorPattern <String>
If the external command raises an exception, match the exception against this regex to determine if the
command can be retried.
If a match is found, the command will be retried provided [maxRetries] has not been reached.
Required? false
Position? 4
Default value
Accept pipeline input? false
Accept wildcard characters? false
-workingDirectory <String>
The working directory to set before running the external command.
Required? false
Position? 5
Default value
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>exec { svn info $repository_trunk } "Error executing SVN. Please verify SVN command-line client is
installed"
This example calls the svn command-line client.
RELATED LINKS
Assert
FormatTaskName
Framework
Get-PSakeScriptTasks
Include
Invoke-psake
Properties
Task
TaskSetup
TaskTearDown
Properties
SYNOPSIS
Helper function for executing command-line programs.
SYNTAX
Exec [-cmd] <ScriptBlock> [[-errorMessage] <String>] [[-maxRetries] <Int32>] [[-retryTriggerErrorPattern]
<String>] [[-workingDirectory] <String>] [<CommonParameters>]
DESCRIPTION
This is a helper function that runs a scriptblock and checks the PS variable $lastexitcode to see if an error
occcured.
If an error is detected then an exception is thrown.
This function allows you to run command-line programs without having to explicitly check fthe $lastexitcode
variable.
PARAMETERS
-cmd <ScriptBlock>
The scriptblock to execute. This scriptblock will typically contain the command-line invocation.
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-errorMessage <String>
The error message to display if the external command returned a non-zero exit code.
Required? false
Position? 2
Default value ($msgs.error_bad_command -f $cmd)
Accept pipeline input? false
Accept wildcard characters? false
-maxRetries <Int32>
The maximum number of times to retry the command before failing.
Required? false
Position? 3
Default value 0
Accept pipeline input? false
Accept wildcard characters? false
-retryTriggerErrorPattern <String>
If the external command raises an exception, match the exception against this regex to determine if the
command can be retried.
If a match is found, the command will be retried provided [maxRetries] has not been reached.
Required? false
Position? 4
Default value
Accept pipeline input? false
Accept wildcard characters? false
-workingDirectory <String>
The working directory to set before running the external command.
Required? false
Position? 5
Default value
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>exec { svn info $repository_trunk } "Error executing SVN. Please verify SVN command-line client is
installed"
This example calls the svn command-line client.
RELATED LINKS
Assert
FormatTaskName
Framework
Get-PSakeScriptTasks
Include
Invoke-psake
Properties
Task
TaskSetup
TaskTearDown
Properties