我正在尝试执行以下terminal命令来输出一些doc文件:
"02:00:00:04" -s doc > 111.doc
还必须通过node.js
:
var exec = require('child_process').exec;
var spawn = require('child_process').spawn;
var fs = require('fs');
var workDir = process.env.TSHARK
var args = ['02:00:00:04' ,'-S','doc']
logStream = fs.createWriteStream(workDir + '//111.doc');
var spawn = require('child_process').spawn,
child = spawn('tshark', args, {cwd: workDir});
child.stdout.pipe(logStream);
child.stderr.pipe(logStream);
child.stdout.on('data', function(data) {
console.log('stdout: ' + data);
});
child.stderr.on('data', function(data) {
console.log('stderr: ' + data);
});
child.on('close', function(code) {
console.log('closing code: ' + code);
});
直接运行terminal命令输出有效文件
但是运行上面的节点脚本没有得到完整的文件(最后一行丢失)。
我的代码出了什么问题?