Home > database >  How to run 2 and more npm tasks in parallell by ".sh" file at Windows?
How to run 2 and more npm tasks in parallell by ".sh" file at Windows?

Time:07-16

Completely novice at ".sh" at the moment when asked this question. I even not sure on what .sh" refering - Shell, Powershell, Bourne shell, etc, but currently I am working from the Windows OS.

What I want to do in this question is:

  1. Change directory
  2. Run the npm script (if to run it will be executed while will not be killed)
  3. Change directory
  4. Run other npm script (if to run it will be executed while will not be killed)

Thus 2 and 4 must being executed while not killed.

My initial code is:

cd UAA_Generators/JapaneseSyntax/ByNodeJS/DataStructures/Tokens || exit
npm run "Incremental building"

cd ../ModulesCollection || exit
npm run "Incremental building"

Currently only first task has deen executed.

CodePudding user response:

I had some difficulties understanding exactly what you mean with "(if to run it will be executed while will not be killed)".
If you want the npm runs to execute as background tasks, meaning the script will proceed without waiting for the command to finish you can add the & operator at the end of the line.
In this example the script will run "incremental building" as a background job, switch directory and then run "Incremental building" in the ModulesCollection directory.

#!bin/bash
cd UAA_Generators/JapaneseSyntax/ByNodeJS/DataStructures/Tokens 
npm run "Incremental building" &

cd ../ModulesCollection 
npm run "Incremental building"

If you simply want them both to run and not wait for them to end before ending your script just add another '&' after each npm run.

Not sure why you included the || Exit after your switching directories, is there some part of your code you left out?
Otherwise it's generally a bad idea to exit your shell before you are done and is most probably the reason for your script not running properly in the first place.

  • Related