我试图使用execFile并记录给出任务完成百分比的stdOut,但是回调函数:
var child = require('child_process');
child.execFile("path/to/the/file", options, function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
});等待进程完成,然后立即记录所有内容。如何在处理过程中获取信息并将其分段记录?,我已经尝试如下:
child.stdout.on('data', function (data) {
console.log(data);
});但是我得到了一个错误:Cannot read property 'on' of undefined"
发布于 2015-01-12 00:10:32
您应该使用.spawn()而不是.exec()/.execFile()来流输出:
var spawn = require('child_process').spawn;
var child = spawn("path/to/the/file", args);
child.stdout.on('data', function(data) {
console.log(data.toString());
});
child.on('close', function(code, signal) {
// process exited and no more data available on `stdout`/`stderr`
});https://stackoverflow.com/questions/27893565
复制相似问题