我可以在 node.js 中使用 child-process 和 spawn cmd,我希望将此命令的输出写入文件而不是 stdout。
测试.js
const expect = require('chai').expect;
const { spawn } = require('child_process')
let path = require('path');
let fs = require('fs');
//tried but didn't work
1) const cmd = spawn(ansysfnonetclient, options, {
stdio: [
0, // Use parent's stdin for child.
'pipe', // Pipe child's stdout to parent.
fs.openSync('err.out', 'w') // Direct child's stderr to a file.
]
});
2) const cmd = spawn(ansysfnonetclient, options, {shell: true, stdio: 'inherit'});
it('run the cmd and write o/p to file', function (done) {
this.timeout(30000);
let options = ['-h','-o','temp.log'];
let ansysfnonetclient = path.resolve(__dirname,'../../../../../../../../saoptest/annetclient.exe');
const cmd = spawn(ansysfnonetclient, options, {shell: true, stdio: 'inherit'});
console.log(cmd);
done();
});
慕无忌1623718
慕标5832272
相关分类