디스크 사용을 분석하기 위해 Node.js 스크립트를 만들려고합니다. 이를 위해 du
으로 나가지만, 줄 단위로 자식 프로세스의 출력을 읽는 방법을 알아 내려는 데 문제가 있습니다.Node.js에서 한 줄씩 child_process를 읽는 방법?
var spawn = require("child_process").spawn,
rl = require('readline'),
du = spawn('du', ['/home']);
linereader = rl.createInterface(du.stdout, du.stdin);
// Read line by line.
//du.stdout.on('data', function (data) {
linereader.on('line', function (data) {
console.log(data);
});
du.stdout.on('data'
단지 데이터의 청크를 읽고, readline
가정으로 라인으로 입력을 분할해야하지만, 대신 나는 정확히 같은 데이터를 얻을,하지 (du.stdout을 수행 여기에 지금까지 시도했습니다 무엇 버퍼를 반환하지만, 을 호출하면 나에게 linereader
과 같은 데이터를 제공합니다.)
아, 알겠습니다. Kinda 슬픈 :) – mikl