2 回答
TA贡献1744条经验 获得超4个赞
stdio
选项传递 3 个“文件”:
输入
输出
错误输出
如果要将常规输出通过管道传输到文件,则必须将该文件作为第二项传递stdio
:
const { spawn } = require('child_process');
const fs = require('fs');
const stdio = [
0,
fs.openSync('std.out', 'w'),
fs.openSync('err.out', 'w')
];
const child = spawn('echo', ['hello world!'], {stdio});
在https://nodejs.org/api/child_process.html#child_process_options_stdio阅读更多相关信息。
TA贡献1966条经验 获得超4个赞
const expect = require('chai').expect;
const { spawn } = require('child_process')
let path = require('path');
let fs = require('fs');
```
const cmd = spawn(ansysfnonetclient, options, {shell: true, stdio: 'inherit'});
cmd.stdout.on('data',function(chunk) {
fs.writeFile(path.resolve(__dirname,'../../../../../../../../output.log'), chunk.toString(), function(err) {
if(err)
{
return console.log(err);
}
console.log("The file was saved!");
});
```
添加回答
举报