为什么这个 Windows 批处理文件只执行第一行,而所有三行都在命令 shell 中执行? [英] Why does only the first line of this Windows batch file execute but all three lines execute in a command shell?

查看:62
本文介绍了为什么这个 Windows 批处理文件只执行第一行,而所有三行都在命令 shell 中执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个批处理文件,一个接一个地执行三个 Maven 命令.每个命令都可以在脚本中成功执行——单独执行!.但是当我将所有三个命令添加到同一个文件时,只有第一个在脚本退出之前执行.知道为什么吗?

I have a batch file that executes three Maven commands, one after the other. Each command can be successfully executed in the script - by itself!. But when I add all three commands to the same file, only the first one executes before the script exits. Any idea why?

mvn install:install-file -DgroupId=gdata -DartifactId=base -Dversion=1.0 -Dfile=gdata-base-1.0.jar  -Dpackaging=jar -DgeneratePom=true
mvn install:install-file -DgroupId=gdata -DartifactId=blogger -Dversion=2.0 -Dfile=gdata-blogger-2.0.jar  -Dpackaging=jar -DgeneratePom=true
mvn install:install-file -DgroupId=gdata -DartifactId=blogger-meta -Dversion=2.0 -Dfile=gdata-blogger-meta-2.0.jar  -Dpackaging=jar -DgeneratePom=true

另外,如果我复制所有三个命令并将它们粘贴到命令 shell (cmd.exe) 中,它们会一个接一个地执行,没有问题.所以这显然是dos批处理文件的一些问题.

Also, if I copy all three commands and paste them into a command shell (cmd.exe), they execute one after the other with no problem. So this is apparently some issue with the dos batch file.

推荐答案

Maven 使用批处理文件来执行它的业务.对于任何批处理脚本,您必须使用 call 命令,因此它知道在被调用脚本完成后返回到您的脚本.尝试在所有命令前添加 call.

Maven uses batch files to do its business. With any batch script, you must call another script using the call command so it knows to return back to your script after the called script completes. Try prepending call to all commands.

您可以尝试的另一件事是使用 start 命令应该类似地工作.

Another thing you could try is using the start command which should work similarly.

这篇关于为什么这个 Windows 批处理文件只执行第一行,而所有三行都在命令 shell 中执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆