0

这是我第一次处理批处理文件。我有一个带有 ant 的 java 项目。我已将项目分为两个子项目。我尝试使用批处理文件按顺序构建项目。这是我的 .bat 文件的内容:

start cmd
cd /d C:\Users\MeUser\Downloads\selenium-grid-1.0.8\examples\java2
ant run

cd /d C:\Users\MeUser\Downloads\selenium-grid-1.0.8\examples\java3
ant run

前三行运行正常,但之后没有任何反应。最后两行不起作用。我是否遗漏了什么,或者是否有其他方法可以按顺序运行这些子项目?谢谢你。

4

1 回答 1

1

is ant a batch file?

If so, try (or try anyway)

CALL ant run

OR

START "windowname" ant run

where you can add /wait to the START command to have the batch wait for the first ant to finish before proceeding.

see

`start /?`

from the prompt for docco.


(following comment)

Here is your original code:

start cmd
cd /d C:\Users\MeUser\Downloads\selenium-grid-1.0.8\examples\java2
ant run

cd /d C:\Users\MeUser\Downloads\selenium-grid-1.0.8\examples\java3
ant run

What this should have done is:

  1. Start a brand-new CMD window
  2. change to the specified sirectory
  3. Start the executable ant with the parameter run

Now - I've just downloaded ANT and I find that it includes ANT.BAT and ANT.CMD but NOT ANT.EXE.

In your environment, you would have a variable called PATHEXT whis is a semicolon-separated list of the valid executable extensions, in order of selection. In all probability, unless you've taken specific action to change it, this will be PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC

What this means is that the ANT that will be executed is ANT.BAT if you've added its directory to your path (which, I believe, is in the instructions)

So executing the ANT.BAT will TRANSFER execution to ANT.BAT.

SO:

I see no reason why you are producing a new CMD window.

cd /d C:\Users\MeUser\Downloads\selenium-grid-1.0.8\examples\java2
CALL ant run

cd /d C:\Users\MeUser\Downloads\selenium-grid-1.0.8\examples\java3
CALL ant run

should work.

cd /d C:\Users\MeUser\Downloads\selenium-grid-1.0.8\examples\java2
START /wait "First ANT" ant run

cd /d C:\Users\MeUser\Downloads\selenium-grid-1.0.8\examples\java3
START /wait "Second ANT" ant run

should also work.

Note the position of the /wait If it follows the start then cmd knows it's a start parameter. If it follows ant then cmd will assume it's an ant parameter.

The /wait simply tells CMD to WAIT until the executable is finished before continuing.

This:

cd /d C:\Users\MeUser\Downloads\selenium-grid-1.0.8\examples\java2
START "First ANT" ant run

cd /d C:\Users\MeUser\Downloads\selenium-grid-1.0.8\examples\java3
START "Second ANT" ant run

should also work, but this time the second ANT instance will be started in parallel with the first (well, milliseconds later)

Note also the "quoted string" before the ant. The syntax of the START statement is to allow a "quoted string" as a window title. The quoted string may be empty "" if you wish. You can even omit the quoted string altogether EXCEPT if the executable is quoted, in which case the window title is required.

于 2013-04-08T09:44:17.407 回答