【发布时间】:2021-09-08 14:57:21
【问题描述】:
我是 node js 的新手,我想在 node js 中执行一个命令,并希望将命令的运行状态显示到终端以及一些日志文件。
// Displaying the output in terminal but I am not able to access child.stdout
const child = spawn(command,[], {
shell: true,
cwd: process.cwd(),
env: process.env,
stdio: 'inherit',
encoding: 'utf-8',
});
// Pushing the output to file but not able to do live interaction with terminal
const child = spawn(command,[], {
shell: true,
cwd: process.cwd(),
env: process.env,
stdio: 'pipe',
encoding: 'utf-8',
});
两者都可以吗?请帮我解决这个问题?
提前致谢。
【问题讨论】:
标签: javascript node.js child-process spawn