Runs the specified program or command with the specified arguments.
The following table describes the parameters for the Exec task.
|
Parameter |
Description |
|---|---|
|
Command |
Required String parameter. The command(s) to run. These can be system commands, such as attrib, or an executable, such as program.exe, runprogram.bat, or setup.msi. This parameter can contains multiple lines of commands. Alternatively, you can place multiple commands in a batch file and run it using this parameter. |
|
ExitCode |
Optional Int32 output read-only parameter. Specifies the exit code provided by the executed command. |
|
IgnoreExitCode |
Optional Boolean parameter. If true, the task ignores the exit code provided by the executed command. Otherwise, the task returns false if the executed command returns a non-zero exit code. |
|
Outputs |
Optional ITaskItem[] output parameter. Contains the output items from the task. The Exec task does not set these itself. Instead, you can provide them as if it did set them, so that they can be used later in the project. |
|
StdErrEncoding |
Optional String output parameter. Specifies the encoding of the captured task standard error stream. The default is the current console output encoding. |
|
StdOutEncoding |
Optional String output parameter. Specifies the encoding of the captured task standard output stream. The default is the current console output encoding. |
|
Timeout |
Optional Int32 parameter. Specifies the amount of time, in milliseconds, after which the task executable is terminated. The default value is Int.MaxValue, indicating that there is no time out period. |
|
ToolPath |
Optional String parameter. Specifies the location from where the task will load the underlying executable file (cmd.exe). |
|
WorkingDirectory |
Optional String parameter. Specifies the directory in which the command will run. |
This task is useful when a specific MSBuild task for the job that you want to perform is not available. One disadvantage of using the Exec task rather than a more specific task is that it cannot gather output from the tool or command that it runs.
The Exec task calls cmd.exe instead of directly invoking a process.
The following example uses the Exec task to run a command.
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Binaries Include="*.dll;*.exe"/>
</ItemGroup>
<Target Name="SetACL">
<!-- set security on binaries-->
<Exec Command="echo y| cacls %(Binaries.Identity) /G everyone:R"/>
</Target>
</Project>
Concepts
Other Resources
In the description, it says "... cannot gather output from the tool or command that it runs." but in the parameters list there is one named Outputs. I don't understand what Outputs is for. Someone please explain & give an example on using it. Thank you!
An easier way to quote parameters or commands (because they contain spaces) is using single quotes around the attribute value and regular quotes in the value.
For example:
<Exec Command='"C:\Program Files\Black Duck Software\protexIP\bin\bdstool" login' WorkingDirectory="$(MSBuildProjectDirectory)"/>
- CustomErrorRegularExpression
- CustomWarningRegularExpression
- IgnoreStandardErrorWarningFormat
I've posted more information on my blog at:
http://www.sedodream.com/PermaLink,guid,4571716d-c40b-4052-828f-ae2c23727e70.aspx
=================
Sayed Ibrahim Hashimi
www.sedodream.com
For example:
<Exec Command=""C:\Program Files\Black Duck Software\protexIP\bin\bdstool" login"
WorkingDirectory="$(MSBuildProjectDirectory)"/>
The reason for this is that the Exec task embeds this Command in an (undocumented) batch script of its own, and without the CALL command the outer batch will not resume execution.
This is a problem on Windows XP but on Windows 7 (and possibly XP) a change to the behaviour of CMD.EXE seems to have eliminated this problem.
For more details, see my blog post:
http://www.danielfortunov.com/software/$daniel_fortunovs_adventures_in_software_development/2009/05/21/invoking_batch_files_from_msbuild