Skip to content
Advertisement

How to wait for a process in a JS NPM script using ShellJS

Node version: v.10.15.3

ShellJS version: 0.8.3

Operating system: Windows 10

Is it possible to wait for a process to finish and then start another one using the wait command in a windows system in a NodeJS script?

I have tried the below, there are no errors, but the echoes are not printed and the script some_npm_script is not executed, is it possible? like I did below? This works in a Linux machine BTW.

Commands like shell.exec(truncate -s 0 ./somefile.js) works and but I do not see the truncate command in the source on the ShellJS module.

shell.exec(`
echo "Installing"
yarn add some_npm_package &
pid=$!
wait $pid
echo "Done installing"
yarn some_npm_script
`);

Any assistance is appreciated, any explanation on why it is not working or any solution or resources, thanks.

Advertisement

Answer

I’ve achieved my goal by moving that specific piece of code into a bash/sh NPM script, and then I have used the shell.exec function froom shellJS to execute the bash NPM script in the JS NPM script like:

shell.exec(yarn bash_npm_script_name) // the script that uses the wait command

So this worked for me, it waited for the package to be installed and then run a script after it was finished.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement