0

I want to run a bat file, in which I have two commands to execute sequentially.

@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

first command executes successfully and line taking input for second command comes,but terminal gets closed and second command is not executed.

2 Answers 2

2

You may be better off using an else clause:

@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
Sign up to request clarification or add additional context in comments.

Comments

0

An EXIT /B instruction exits from the current routine, hence the routine will be exited once mvn versions:set -Dne... has ended.

7 Comments

even if I remove all EXIT /B , it is still not working
What is mvn? If mvn is a batch file (mvn.bat) then you need call mvn in order to have batch return to the procedure after completing mvn.
I removed EXIT /B and applied call before mvn command. first command executed and second input statement prompted but after entering a key, it showed an error : goto was unexpected at this time.
%~1 refers to the first parameter provided to the batch file. You need (eg) if "%commitChanges%"=="y" .... note that if /i... will perform a case-insensitive comparison.
@echo off set /p productVersion="Enter new product version: " call 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% :commitChanges If "%commitChanges%"=="y" ( mvn versions:commit ) IF "%commitChanges%"=="n" ( mvn versions:revert ) IF "%commitChanges%"=="Y" ( mvn versions:commit ) IF "%commitChanges%"=="N" ( mvn versions:revert )
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.