Created
December 24, 2021 02:47
-
-
Save oze4/6235640ca6cc59faecee9e275bff65d6 to your computer and use it in GitHub Desktop.
child_process.spawn node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://stackoverflow.com/a/10232330/10431732 | |
const childProcess = require('child_process'); | |
// just runs `ls -a ../` | |
const childp = childProcess.spawn('ls', ['-a', '../']); | |
// assign stdout to variable | |
const variable = chilldp.stdout; | |
// listen for events on that variable | |
variable.on('data', (data) => { | |
console.log('stdout: ' + data.toString()); | |
}); | |
// You can listen for many events | |
childp.stderr.on('data', (data) => { | |
console.log('stderr: ' + data.toString()); | |
}); | |
childp.on('exit', (code) => { | |
console.log('child process exited with code ' + code.toString()); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment