7

I know one can run two commands in one line in Windows CMD like this:

dir & echo foo

But how could one run two commands parallel? I also know that one can achieve this by using START. But then you have to put those commands into a batch file. I would want to launch them parallel from the command line itself.

What I would like to achieve is something like this:

set NODE_ENV=development&& nodemon -e js,jsx,cjsx,css,scss,html,coffee --watch ./app/ server/server.js & set NODE_ENV=development&& node server/hotLoadServer.js

If I run the commands separately in separate windows, they work perfect. But I cannot seem to get them run as a one liner in one cmd prompt. What happens is, the first one is run, the second is not. The first one will remain open, and the second one is never executed.

Ville Miekk-oja
  • 18,749
  • 32
  • 70
  • 106
  • I think the only chance is using `start` as this does not wait for the command to quit; like `start "" "commandline1" & start "" "commandline2"... – aschipfl Oct 09 '15 at 00:55
  • Didn't work, I tried: start "" "set NODE_ENV=development&& nodemon -e js,jsx,cjsx,css,scss,html,coffee --watch ./app/ server/server.js" & start "" "set NODE_ENV=development&& node server/hotLoadServer.js". It prompted: "Windows cannot find "command above".... – Ville Miekk-oja Oct 09 '15 at 06:52
  • Perhaps you need to provide full paths...? – aschipfl Oct 09 '15 at 08:59
  • Does this answer your question? [How to run multiple DOS commands in parallel?](https://stackoverflow.com/questions/11010834/how-to-run-multiple-dos-commands-in-parallel) – Георги Кременлиев Oct 27 '20 at 06:42

2 Answers2

6

This executes two tasks in parallel and open one window for each:

# powershell
start ping google.com; start ping example.com
# cmd
start ping google.com & start ping example.com

This does the same, but the /B option prevents any new window from opening (in cmd):

start /B ping google.com & start ping example.com

I didn't find any direct equivalent in powershell, although starting this in powershell does the trick:

cmd /C 'start /B ping google.com & start /B ping example.com'

Note also that powershell's Start-Job cmdlet allows users to start background jobs.

Nino Filiu
  • 16,660
  • 11
  • 54
  • 84
0

You can run parallel threads in one cmd session. use 'cmd' command with /c parameter, it will Carries out the command specified by string and then stops. e.g cmd /c echo done

for more reference :https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/cmd.mspx?mfr=true

  • Thanks, but didn't work. It carried on the first command, and since the first command never ended (it was a server), it never reached to the second command. I added more to the original post, please check that. – Ville Miekk-oja Oct 08 '15 at 19:41
  • Perhaps `cmd /K` could help? – aschipfl Oct 09 '15 at 01:00
  • /K means "Carries out the command specified by string but remains" if you checkout the help shown by /? - so shouldn't be useful for running things in parallel – George Birbilis Jul 15 '21 at 20:19