Skip to content

Instantly share code, notes, and snippets.

@nomeyer
Created February 25, 2016 14:16
Show Gist options
  • Save nomeyer/90ce9b321fbf8cbff3da to your computer and use it in GitHub Desktop.
Save nomeyer/90ce9b321fbf8cbff3da to your computer and use it in GitHub Desktop.
Spawn a child process with command line arguments in node.js
const spawn = require('child_process').spawn;
const ls = spawn('ls', ['-lh', '/usr']);
ls.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
});
ls.stderr.on('data', (data) => {
console.log(`stderr: ${data}`);
});
ls.on('close', (code) => {
console.log(`child process exited with code ${code}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment