[英]Is there a way to get 'live' output lines from a python script spawned by child_process.execFile without flushing stdout every time?
[英]get execFile stdOut on chunks
我正在嘗試使用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"
您應該使用.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`
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.