반응형
노드 child_process를 사용하는 Stdout 버퍼 문제
로컬 네트워크의 공유 폴더에서 JSON 파일 (약 220Ko)을 가져 오기 위해 node child_process를 사용하여 curl을 실행하려고합니다. 그러나 실제로 얻을 수없는 버퍼 문제를 반환합니다. 내 코드는 다음과 같습니다.
var exec = require('child_process').exec;
var execute = function(command, callback){
exec(command, function(error, stdout, stderr){ callback(error, stdout); });
};
execute("curl http://" + ip + "/file.json", function(err, json, outerr) {
if(err) throw err;
console.log(json);
})
그리고 여기에 내가 얻는 오류가 있습니다.
if(err) throw err;
^
Error: stdout maxBuffer exceeded.
at Socket.<anonymous> (child_process.js:678:13)
at Socket.EventEmitter.emit (events.js:95:17)
at Socket.<anonymous> (_stream_readable.js:746:14)
at Socket.EventEmitter.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:408:10)
at emitReadable (_stream_readable.js:404:5)
at readableAddChunk (_stream_readable.js:165:9)
at Socket.Readable.push (_stream_readable.js:127:10)
at Pipe.onread (net.js:526:21)
을 (를) 사용할 maxBuffer때 옵션 을 사용하고 설정해야합니다 child_process.exec. 로부터 문서 :
maxBufferstdout 또는 stderr에 허용되는 최대 데이터 양을 지정합니다.이 값이 초과되면 하위 프로세스가 종료됩니다.
문서에는 기본값 maxBuffer이 200KB 라고도 나와 있습니다.
예를 들어 다음 코드에서는 최대 버퍼 크기가 500KB로 증가합니다.
var execute = function(command, callback){
exec(command, {maxBuffer: 1024 * 500}, function(error, stdout, stderr){ callback(error, stdout); });
};
또한, 당신이하려는 일을 http.get성취 할 수 있는지 읽어보기를 원할 수도 있습니다 .
비슷한 문제가 있었고 exec에서 spawn으로 이동하는 문제를 해결했습니다.
var child = process.spawn('<process>', [<arg1>, <arg2>]);
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('child process exited with code ' + code);
});
참고 URL : https://stackoverflow.com/questions/23429499/stdout-buffer-issue-using-node-child-process
반응형
'Programing' 카테고리의 다른 글
| 'DataFrame'개체에 'sort'속성이 없습니다. (0) | 2020.10.07 |
|---|---|
| jquery-chosen 드롭 다운 비활성화 (0) | 2020.10.07 |
| 인형을위한 재귀 체계? (0) | 2020.10.06 |
| 문자열의 소문자 및 대문자 버전이 존재하는 이유는 무엇이며 어떤 것을 사용해야합니까? (0) | 2020.10.06 |
| API 게이트웨이 대 역방향 프록시 (0) | 2020.10.06 |