Skip to content

Instantly share code, notes, and snippets.

@cliffano
Last active December 19, 2015 09:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cliffano/5931066 to your computer and use it in GitHub Desktop.
Save cliffano/5931066 to your computer and use it in GitHub Desktop.
child_process bg
>>> cat blah.js
var cp = require('child_process');
var c = cp.exec('./blah.sh &', function (err) {
if (err) {
console.error('err: ' + err.message);
} else {
console.log('done');
}
});
c.stderr.on('data', function (data) {
console.error('stderr: ' + data);
});
c.stdout.on('data', function (data) {
console.log('stdout: ' + data);
});
>>> cat blah.sh
#!/bin/bash
for x in {1..5}
do
echo "numero: $x"
sleep 2
done
>>> node blah.js
(won't exit until blah.sh is done even though it's meant to run in the background)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment