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 10 KiB

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