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

Share:
12,953

Related videos on Youtube

Mr.B
Author by

Mr.B

Aspiring to write better code, create useful applications and greater mankind.

Updated on September 18, 2022

Comments

  • Mr.B
    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 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
    
    • Jeff Zeitlin
      Jeff Zeitlin almost 7 years
      Why are you executing npm via a separate cmd instance?
    • Erlis D.
      Erlis D. almost 7 years
      I'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 first cmd instance. Since gulp needs npm, it will return an error as for the first cmd instance npm is not installed. The commands on the first cmd instance still continue even if npm install was not finished installing on the second cmd instance. That's whats causing the issue in my opinion.