最佳答案
我尝试使用 node child _ process 执行 curl,以便从本地网络中的共享文件夹获取一个 JSON 文件(大约220Ko)。但它实际上返回了一个我无法解决的缓冲区问题。 这是我的代码:
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)