how to exec command in new prompt using ant

2019-07-31 22:53发布

问题:

I am trying to run a command in ant to start the selenium server but it opens up in the same command prompt, is there anyway i can open it up in a new prompt?

<project>
<target name="startGRID">
    <exec dir="." executable="cmd">
        <arg value="/c"/>
        <arg value="java -jar selenium-server-standalone-2.43.1.jar -role hub"/>
    </exec>
</target>
</project>

回答1:

To see a separate command prompt in which your server is run, use the dos start command, which does exactly that:

<exec dir="." executable="cmd">
  <arg value="/c"/>
  <arg value="start"/>
  <arg value="java -jar selenium-server-standalone-2.43.1.jar -role hub"/>
</exec>

The only issue I find with that is that, when the server is terminated, the new command prompt window will remain open. This can be worked around by wrapping the java command in a batch script, let's call it start-selenium.bat, with an exit statement at the end:

java -jar selenium-server-standalone-2.43.1.jar -role hub
exit

then the Ant task becomes:

<exec dir="." executable="cmd">
  <arg value="/c"/>
  <arg value="start"/>
  <arg value="start-selenium.bat"/>
</exec>


标签: selenium ant