在块上获取execFile stdOut [英] get execFile stdOut on chunks
本文介绍了在块上获取execFile stdOut的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用execFile并记录stdOut,该值给出了完成任务的百分比,但是有回调函数:
I am trying to use execFile and log the stdOut that gives the percentage done on the task, but the callback function:
var child = require('child_process');
child.execFile("path/to/the/file", options, function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
});
等待直到该过程完成,然后立即记录所有内容. 在处理过程中如何获取信息并将其部分记录?,我已经尝试过:
Waits until the process is done and then logs everything at once. How do i get the info while is being processed and log it in parts?, I have try this:
child.stdout.on('data', function (data) {
console.log(data);
});
但是我收到此错误:Cannot read property 'on' of undefined"
推荐答案
您应使用 .spawn()
而不是.exec()
/.execFile()
来流输出:
You should use .spawn()
instead of .exec()
/.execFile()
for streaming the output:
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`
});
这篇关于在块上获取execFile stdOut的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文