Windows Batch File: How to run multiple batch commands?
12,953
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
- An A-Z Index of the Windows CMD command line
- A categorized list of Windows CMD commands
- cmd - Start a new CMD shell and (optionally) run a command/executable program.
Related videos on Youtube
Author by
Mr.B
Aspiring to write better code, create useful applications and greater mankind.
Updated on September 18, 2022Comments
-
Mr.B over 1 year
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
andCALL
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
-
Jeff Zeitlin almost 7 yearsWhy are you executing
npm
via a separatecmd
instance? -
Erlis D. almost 7 yearsI'm thinking since you open a new
cmd
instance, the other commands past that don't run as they try to install packages on the firstcmd
instance. Sincegulp
needsnpm
, it will return an error as for the firstcmd
instancenpm
is not installed. The commands on the firstcmd
instance still continue even ifnpm install
was not finished installing on the secondcmd
instance. That's whats causing the issue in my opinion.
-