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.3 KiB

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