0

I'm trying to script everything. How could I run multiple instances of npm start in one .cmd file for Windows ?

Example : I've got an API which runs with "npm start" and a client app which also runs with "npm start". I can easily run a single one with :

cd D:/my folder/... 
npm start

But here, i would like to open a second command prompt in order to cd another folder and run another "npm start" with the same .cmd file.

Thank you !

Compo
  • 36,585
  • 5
  • 27
  • 39
Horkos
  • 227
  • 2
  • 5
  • 12
  • 1
    Can you use `start /b` as discussed here? https://stackoverflow.com/questions/21031171/how-to-run-a-command-in-the-background-on-windows That will run that npm start in the background and you can do other things like launch another one while that runs. – Stephan Pieterse Jun 25 '21 at 10:13

2 Answers2

1

is really another batch file, so it should be called. When you call a batch file from another, it will return to the caller upon completion:

@Echo Off
CD /D "D:\Somewhere"
Call "P:\athTo\npm.cmd" start [-- <args>]
CD /D "C:\AnotherPlace"
Call "P:\athTo\npm.cmd" start [-- <args>]
Rem next line if required goes here

As your question did not require that both commands needed to be run at the same time, (or that a second Command Prompt was a necessity), the answer above is based upon that.

Compo
  • 36,585
  • 5
  • 27
  • 39
0

I found a workaround by running multiple .cmd files from the first one, and then exiting it, like this :

cd D:/.../folder
start script1.cmd
start script2.cmd
exit

This way, you can run as many commands as you want, and even with different titles etc. Kind of messy, but everyone needs a folder full of .cmd files, right ?

Horkos
  • 227
  • 2
  • 5
  • 12
  • I cannot agree. I don't need a folder full of cmd files as I know how to code a batch file correct for a task to accomplish with a batch file. The command `exit` at end of a batch file is never necessary and is just counterproductive on running the batch file from within a command prompt window instead of double clicking on the batch file. So I would strongly recommend to remove `exit` at end of your batch file. – Mofi Jun 25 '21 at 14:16