Skip to content

Instantly share code, notes, and snippets.

@dshaw
Created March 22, 2012 04:45
Show Gist options
  • Save dshaw/2156098 to your computer and use it in GitHub Desktop.
Save dshaw/2156098 to your computer and use it in GitHub Desktop.
Continuously keep respawning a child process
var exec = require('child_process').exec;
function respawn () {
var child = exec('date', function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) console.log('exec error: ' + error);
});
child.on('exit', function (code, signal) {
console.log('exit code: ', code);
console.log('exit signal: ', signal);
console.warn('\nCNTL-C to exit.\n');
child = respawn();
});
}
respawn();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment