You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

exec.html 7.8 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Language" content="en-us">
  4. <title>Exec Task</title>
  5. </head>
  6. <body>
  7. <h2><a name="exec">Exec</a></h2>
  8. <h3>Description</h3>
  9. <p>Executes a system command. When the <i>os</i> attribute is specified, then
  10. the command is only executed when Ant is run on one of the specified operating
  11. systems.</p>
  12. <h3>Parameters</h3>
  13. <table border="1" cellpadding="2" cellspacing="0">
  14. <tr>
  15. <td valign="top"><b>Attribute</b></td>
  16. <td valign="top"><b>Description</b></td>
  17. <td align="center" valign="top"><b>Required</b></td>
  18. </tr>
  19. <tr>
  20. <td valign="top">command</td>
  21. <td valign="top">the command to execute with all command line
  22. arguments. <b>deprecated, use executable and nested
  23. <code>&lt;arg&gt;</code> elements instead</b>.</td>
  24. <td align="center" rowspan="2">Exactly one of the two.</td>
  25. </tr>
  26. <tr>
  27. <td valign="top">executable</td>
  28. <td valign="top">the command to execute without any command line
  29. arguments.</td>
  30. </tr>
  31. <tr>
  32. <td valign="top">dir</td>
  33. <td valign="top">the directory in which the command should be executed.</td>
  34. <td align="center" valign="top">No</td>
  35. </tr>
  36. <tr>
  37. <td valign="top">os</td>
  38. <td valign="top">list of Operating Systems on which the command may be
  39. executed. If the current OS's name is contained in this list, the command will
  40. be executed. The OS's name is determined by the Java Virtual machine and is set
  41. in the &quot;os.name&quot; system property.</td>
  42. <td align="center" valign="top">No</td>
  43. </tr>
  44. <tr>
  45. <td valign="top">output</td>
  46. <td valign="top">the file to which the output of the command should be
  47. redirected.</td>
  48. <td align="center" valign="top">No</td>
  49. </tr>
  50. <tr>
  51. <td valign="top">append</td>
  52. <td valign="top">whether output should be appended to or overwrite
  53. an existing file. Defaults to false.</td>
  54. <td align="center" valign="top">No</td>
  55. </tr>
  56. <tr>
  57. <td valign="top">outputproperty</td>
  58. <td valign="top">the name of a property in which the output of the
  59. command should be stored.</td>
  60. <td align="center" valign="top">No</td>
  61. </tr>
  62. <tr>
  63. <td valign="top">resultproperty</td>
  64. <td valign="top">the name of a property in which the return code of the
  65. command should be stored. Only of interest if failonerror=false</td>
  66. <td align="center" valign="top">No</td>
  67. </tr>
  68. <tr>
  69. <td valign="top">timeout</td>
  70. <td valign="top">Stop the command if it doesn't finish within the
  71. specified time (given in milliseconds).</td>
  72. <td align="center" valign="top">No</td>
  73. </tr>
  74. <tr>
  75. <td valign="top">failonerror</td>
  76. <td valign="top">Stop the buildprocess if the command exits with a
  77. returncode other than 0. Defaults to false</td>
  78. <td align="center" valign="top">No</td>
  79. </tr>
  80. <tr>
  81. <td valign="top">failifexecutionfails</td>
  82. <td valign="top">Stop the build if we can't start the program.
  83. Defaults to true. </td>
  84. <td align="center" valign="top">No</td>
  85. </tr> <tr>
  86. <td valign="top">newenvironment</td>
  87. <td valign="top">Do not propagate old environment when new environment
  88. variables are specified.</td>
  89. <td align="center" valign="top">No, default is <i>false</i></td>
  90. </tr>
  91. <tr>
  92. <td valign="top">vmlauncher</td>
  93. <td valign="top">Run command using the Java VM's execution facilities
  94. where available. If set to false the underlying OS's shell,
  95. either directly or through the antRun scripts, will be used.
  96. Under some operating systems, this gives access to facilities
  97. not normally available through the VM including, under Windows,
  98. being able to execute scripts, rather than their associated
  99. interpreter. If you want to specify the name of the
  100. executable as a relative path to the directory given by the
  101. dir attribute, it may become necessary to set vmlauncher to
  102. false as well.</td>
  103. <td align="center" valign="top">No, default is <i>true</i></td>
  104. </tr>
  105. </table>
  106. <h3>Examples</h3>
  107. <blockquote>
  108. <pre>
  109. &lt;exec dir=&quot;${src}&quot; executable=&quot;cmd.exe&quot; os=&quot;Windows 2000&quot; output=&quot;dir.txt&quot;&gt;
  110. &lt;arg line=&quot;/c dir&quot;/&gt;
  111. &lt;/exec&gt;</pre>
  112. </blockquote>
  113. <h3>Parameters specified as nested elements</h3>
  114. <h4>arg</h4>
  115. <p>Command line arguments should be specified as nested
  116. <code>&lt;arg&gt;</code> elements. See <a
  117. href="../using.html#arg">Command line arguments</a>.</p>
  118. <h4><a name="env">env</a></h4>
  119. <p>It is possible to specify environment variables to pass to the
  120. system command via nested <code>&lt;env&gt;</code> elements.</p>
  121. <table border="1" cellpadding="2" cellspacing="0">
  122. <tr>
  123. <td valign="top"><b>Attribute</b></td>
  124. <td valign="top"><b>Description</b></td>
  125. <td align="center" valign="top"><b>Required</b></td>
  126. </tr>
  127. <tr>
  128. <td valign="top">key</td>
  129. <td valign="top">The name of the environment variable.</td>
  130. <td align="center" valign="top">Yes</td>
  131. </tr>
  132. <tr>
  133. <td valign="top">value</td>
  134. <td valign="top">The literal value for the environment variable.</td>
  135. <td align="center" rowspan="3">Exactly one of these.</td>
  136. </tr>
  137. <tr>
  138. <td valign="top">path</td>
  139. <td valign="top">The value for a PATH like environment
  140. variable. You can use ; or : as path separators and Ant will
  141. convert it to the platform's local conventions.</td>
  142. </tr>
  143. <tr>
  144. <td valign="top">file</td>
  145. <td valign="top">The value for the environment variable. Will be
  146. replaced by the absolute filename of the file by Ant.</td>
  147. </tr>
  148. </table>
  149. <h3>Errors and return codes</h3>
  150. By default the return code of a &lt;exec&gt; is ignored; when you set
  151. <code>failonerror="true"</code> then any non zero response is treated as an
  152. error. Alternatively, you can set <code>resultproperty</code> to the name
  153. of a property and have it assigned to the result code (barring immutability,
  154. of course).
  155. <p>
  156. If the attempt to start the program fails with an OS dependent error code,
  157. then &lt;exec&gt; halts the build unless <code>failifexecutionfails</code>
  158. is set. You can use that to run a program if it exists, but otherwise
  159. do nothing.
  160. <p>
  161. What do those error codes mean? Well, they are OS dependent. On Windows
  162. boxes you have to look in include\error.h in your windows compiler or wine files;
  163. error code 2 means 'no such program', which usually means it is not on the path.
  164. Any time you see such an error from any ant task, it is usually not an ant bug,
  165. but some configuration problem on your machine.
  166. <h3>Examples</h3>
  167. <blockquote><pre>
  168. &lt;exec executable=&quot;emacs&quot;&gt;
  169. &lt;env key=&quot;DISPLAY&quot; value=&quot;:1.0&quot;/&gt;
  170. &lt;/exec&gt;
  171. </pre></blockquote>
  172. <p>starts <code>emacs</code> on display 1 of the X Window System.</p>
  173. <blockquote><pre>
  174. &lt;exec ... &gt;
  175. &lt;env key=&quot;PATH&quot; path=&quot;${java.library.path}:${basedir}/bin&quot;/&gt;
  176. &lt;/exec&gt;
  177. </pre></blockquote>
  178. <p>adds <code>${basedir}/bin</code> to the <code>PATH</code> of the
  179. system command.</p>
  180. <p><b>Note:</b> Although it may work for you to specify arguments using
  181. a simple arg-element and separate them by spaces it may fail if you switch to
  182. a newer version of the JDK. JDK &lt; 1.2 will pass these as separate arguments
  183. to the program you are calling, JDK &gt;= 1.2 will pass them as a single
  184. argument and cause most calls to fail.</p>
  185. <p><b>Note2:</b> If you are using Ant on Windows and a new DOS-Window pops up
  186. for every command which is executed this may be a problem of the JDK you are using.
  187. This problem may occur with all JDK's &lt; 1.2.</p>
  188. <p>
  189. <b>Timeouts: </b> If a timeout is specified, when it is reached the
  190. sub process is killed and a message printed to the log. The return
  191. value of the execution will be "-1", which will halt the build if
  192. <tt>failonerror=true</tt>, but be ignored otherwise.
  193. <hr>
  194. <p align="center">Copyright &copy; 2000-2002 Apache Software Foundation. All rights
  195. Reserved.</p>
  196. </body>
  197. </html>