Tuesday, March 24, 2015

Windows Batch File: How to run multiple batch commands?


I'm trying to do some basic functionality using a batch file but the batch file opens cmd and runs the first command but then stops, ignoring the other commands. I've tried using START and CALL but neither I have had any success with, can anyone provide advice?


Batch file looks as below:


CD C:\Random\Madeup\Path
cmd.exe /K "npm install"
CALL gulp-publish.BAT
CD C:\Random\Madeup\Path\mobile\dist
REN C:\Random\Madeup\Path\mobile\dist\config.xml config-publish.txt
PAUSE

Answer



The batch file opens cmd and runs the first command but then stops


cmd.exe /K "npm install"

That is what /k is intended to do:


/K     Run Command and then return to the CMD prompt.
This is useful for testing, to examine variables

It runs cmd and then immediately returns to the enclosing cmd shell, which aslo bypasses the rest of the commands in the batch file.


Try replacing that line with:


npm install

or:


call npm install



Further Reading


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...