Skip to content

Instantly share code, notes, and snippets.

@bryanwb
Created May 4, 2010 10:37
Show Gist options
  • Select an option

  • Save bryanwb/389247 to your computer and use it in GitHub Desktop.

Select an option

Save bryanwb/389247 to your computer and use it in GitHub Desktop.
var sys = require('sys'),
spawn = require('child_process').spawn,
ls = spawn('ls', ['-lh', '/usr']);
ls.stdout.addListener('data', function (data) {
sys.print('stdout: ' + data);
});
ls.stderr.addListener('data', function (data) {
sys.print('stderr: ' + data);
});
ls.addListener('exit', function (code) {
sys.puts('child process exited with code ' + code);
});
//Question: Why doesn't the ls child process terminate before event listener for "exit" has been added?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment