128

I created the following file

npminstall.bat:

npm install
echo hello

When I run the following command from Windows 10 Command Line (dos) npminstall.bat, the npm install command fires, but the echo hello doesn't fire. I tried putting a semi-colour after the first line like this npm install;, but all that did was give me the help instructions of npm.

How do I get the second line echo hello to fire after the npm install?

Additional Notes

I have found that this also causes the same behaviour:

npminstall.bat:

webpack
echo hello

I think it's because both the npm install command and webpack command take time to execute, and during that time it doe something I don't expect to the second line.

Followup 2

npminstall.bat:

START /WAIT npm install
echo hello

This seems to almost do what I want to do. Except the npm install command causes a pop-up window, and I have to shut down the pop-up window before it continues execution to echo hello world. Can I get rid of the popup window?

Usitha Indeewara
  • 870
  • 3
  • 10
  • 21
John
  • 32,403
  • 80
  • 251
  • 422

1 Answers1

269

When you access another batch file from a batch file, you need to use the CALL command to return control to parent process otherwise control is passed to the batch file being executed.

call npm install
Squashman
  • 13,649
  • 5
  • 27
  • 36
  • 3
    You are a lifesaver! I am trying to build angular on jenkins and the script never made it past npm install until I added the 'call' ! – Ralph Ritoch Jan 31 '19 at 02:20
  • This allows the script to run but the batch file will no longer detect errors. Hence if something breaks in for example npm build, the batch file will just continue. Any solution for this issue? – muffin May 04 '19 at 15:32
  • 5
    I noticed calling npm also turns _echo_ off. I had to workaround this by following the `call npm install` with `@echo on` – Wyck Jun 12 '19 at 02:04
  • 1
    So apparently npm is a batch file that calls `node.exe` with `npm-cli.js`. Any reasons not to start NPM the same way in our own automation? – Louis Somers Nov 26 '21 at 15:24