Node.js & child_process All In One
Node.js & child_process All In One
https://nodejs.org/api/child_process.html#child_process_options_stdio
https://nodejs.org/api/child_process.html#child-process
demo
// child_process.js
const { spawn } = require('child_process');
// const ls = spawn('ls', ['-lh', '/usr']);
// const ls = spawn('ls', ['-al', '/etc/']);
const ls = spawn('ls', ['-al', '/etc/shells']);
ls.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
});
ls.stderr.on('data', (data) => {
console.error(`stderr: ${data}`);
});
ls.on('close', (code) => {
console.log(`child process exited with code ${code}`);
});
$ node ./child_process.js
refs
https://github.com/xgqfrms/set-process-env/issues/10#issuecomment-946914254
©xgqfrms 2012-2020
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/15427171.html
未经授权禁止转载,违者必究!