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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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">newenvironment</td>
  82. <td valign="top">Do not propagate old environment when new environment
  83. variables are specified.</td>
  84. <td align="center" valign="top">No, default is <i>false</i></td>
  85. </tr>
  86. <tr>
  87. <td valign="top">vmlauncher</td>
  88. <td valign="top">Run command using the Java VM's execution facilities
  89. where available. If set to false the underlying OS's shell,
  90. either directly or through the antRun scripts, will be used.
  91. Under some operating systems, this gives access to facilities
  92. not normally available through the VM including, under Windows,
  93. being able to execute scripts, rather than their associated
  94. interpreter.</td>
  95. <td align="center" valign="top">No, default is <i>true</i></td>
  96. </tr>
  97. </table>
  98. <h3>Examples</h3>
  99. <blockquote>
  100. <pre>
  101. &lt;exec dir=&quot;${src}&quot; executable=&quot;cmd.exe&quot; os=&quot;Windows 2000&quot; output=&quot;dir.txt&quot;&gt;
  102. &lt;arg line=&quot;/c dir&quot;/&gt;
  103. &lt;/exec&gt;</pre>
  104. </blockquote>
  105. <h3>Parameters specified as nested elements</h3>
  106. <h4>arg</h4>
  107. <p>Command line arguments should be specified as nested
  108. <code>&lt;arg&gt;</code> elements. See <a
  109. href="../using.html#arg">Command line arguments</a>.</p>
  110. <h4><a name="env">env</a></h4>
  111. <p>It is possible to specify environment variables to pass to the
  112. system command via nested <code>&lt;env&gt;</code> elements.</p>
  113. <table border="1" cellpadding="2" cellspacing="0">
  114. <tr>
  115. <td valign="top"><b>Attribute</b></td>
  116. <td valign="top"><b>Description</b></td>
  117. <td align="center" valign="top"><b>Required</b></td>
  118. </tr>
  119. <tr>
  120. <td valign="top">key</td>
  121. <td valign="top">The name of the environment variable.</td>
  122. <td align="center" valign="top">Yes</td>
  123. </tr>
  124. <tr>
  125. <td valign="top">value</td>
  126. <td valign="top">The literal value for the environment variable.</td>
  127. <td align="center" rowspan="3">Exactly one of these.</td>
  128. </tr>
  129. <tr>
  130. <td valign="top">path</td>
  131. <td valign="top">The value for a PATH like environment
  132. variable. You can use ; or : as path separators and Ant will
  133. convert it to the platform's local conventions.</td>
  134. </tr>
  135. <tr>
  136. <td valign="top">file</td>
  137. <td valign="top">The value for the environment variable. Will be
  138. replaced by the absolute filename of the file by Ant.</td>
  139. </tr>
  140. </table>
  141. <h5>Examples</h5>
  142. <blockquote><pre>
  143. &lt;exec executable=&quot;emacs&quot; &gt;
  144. &lt;env key=&quot;DISPLAY&quot; value=&quot;:1.0&quot;/&gt;
  145. &lt;/exec&gt;
  146. </pre></blockquote>
  147. <p>starts <code>emacs</code> on display 1 of the X Window System.</p>
  148. <blockquote><pre>
  149. &lt;exec ... &gt;
  150. &lt;env key=&quot;PATH&quot; path=&quot;${java.library.path}:${basedir}/bin&quot;/&gt;
  151. &lt;/exec&gt;
  152. </pre></blockquote>
  153. <p>adds <code>${basedir}/bin</code> to the <code>PATH</code> of the
  154. system command.</p>
  155. <p><b>Note:</b> Although it may work for you to specify arguments using
  156. a simple arg-element and separate them by spaces it may fail if you switch to
  157. a newer version of the JDK. JDK &lt; 1.2 will pass these as separate arguments
  158. to the program you are calling, JDK &gt;= 1.2 will pass them as a single
  159. argument and cause most calls to fail.</p>
  160. <p><b>Note2:</b> If you are using Ant on Windows and a new DOS-Window pops up
  161. for every command which is executed this may be a problem of the JDK you are using.
  162. This problem may occur with all JDK's &lt; 1.2.</p>
  163. <p>
  164. <b>Timeouts: </b> If a timeout is specified, when it is reached the
  165. sub process is killed and a message printed to the log. The return
  166. value of the execution will be "-1", which will halt the build if
  167. <tt>failonerror=true</tt>, but be ignored otherwise.
  168. <hr>
  169. <p align="center">Copyright &copy; 2001-2002 Apache Software Foundation. All rights
  170. Reserved.</p>
  171. </body>
  172. </html>