Skip to content

Instantly share code, notes, and snippets.

@mykeels
Last active April 4, 2018 11:49
Show Gist options
  • Select an option

  • Save mykeels/ed062137bab265c15dbc00aa9eedf643 to your computer and use it in GitHub Desktop.

Select an option

Save mykeels/ed062137bab265c15dbc00aa9eedf643 to your computer and use it in GitHub Desktop.
A simple example showing a Node program invoking the `ls` child process in a unix environment
(() => {
const { spawn } = require('child_process');
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