我想运行一个bat文件,其中有两个命令可以按顺序执行。
@echo off
::taking version no. as input
set /p productVersion="Enter new product version: "
::executing first command
mvn versions:set -DnewVersion=%productVersion% && set /p commitChanges="new version is set for all modules %productVersion% Do you want commit your changes for all pom files :(y/n)" && call:commitChanges %commitChanges%
EXIT /B
::executing second command, after taking input y/n
:commitChanges
If %~1=="y" goto yes
If %~1=="n" goto no
If %~1=="Y" goto yes
If %~1=="N" goto no
EXIT /B
:no
mvn versions:revert
EXIT /B
:yes
mvn versions:commit
EXIT /B
第一个命令成功执行,第二个命令的换行输入到来,但终端关闭,第二个命令没有执行。
答案 0 :(得分:2)
使用else子句可能会更好:
@Echo Off
:AskFirst
Set/P "productVersion=Enter new product version: "
If "%productVersion%"=="" GoTo AskFirst
Call mvn versions:set -DnewVersion=%productVersion%
Echo=new version is set for all modules %productVersion%
:AskSecond
Set/P "commitChanges=Do you want commit your changes for all pom files :(y/n) "
If /I "%commitChanges%"=="y" (Call mvn versions:commit) Else (
If /I "%commitChanges%"=="n" (Call mvn versions:revert) Else (
GoTo AskSecond))
Echo=changes have been committed
Pause
Exit/B
答案 1 :(得分:0)
EXIT /B
指令退出当前例程,因此例程将在mvn versions:set -Dne...
结束后退出。