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

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