Skip to content

Instantly share code, notes, and snippets.

@umidjons
Created August 18, 2016 14:22
Show Gist options
  • Save umidjons/16047079b76e3aef52edb39fc2577a5d to your computer and use it in GitHub Desktop.
Save umidjons/16047079b76e3aef52edb39fc2577a5d to your computer and use it in GitHub Desktop.
Spawn child process example

Spawn child process example

'use strict';

var spawn = require('child_process').spawn,
    pwd = spawn('cmd', ['/c', 'dir']);

pwd.stdout.on('data', (data) => {
    console.log('stdout:', data.toString());
});

pwd.stderr.on('data', (data) => {
    console.log('stderr:', data.toString());
});

pwd.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