Node.js 带缓冲区的节点js getasync
我正在使用getasync执行一些cmd命令,它给了我以下错误:Node.js 带缓冲区的节点js getasync,node.js,buffer,getasync,Node.js,Buffer,Getasync,我正在使用getasync执行一些cmd命令,它给了我以下错误: Unhandled rejection RangeError [ERR_CHILD_PROCESS_STDIO_MAXBUFFER]: stderr maxBuffer length exceeded 输出相当大,但我需要它来调试底层python脚本。。有没有办法放大maxBuffer?请参阅我的代码: thecaller: function(req, callback) { const geoJSON = req.geoJS
Unhandled rejection RangeError [ERR_CHILD_PROCESS_STDIO_MAXBUFFER]: stderr maxBuffer length exceeded
输出相当大,但我需要它来调试底层python脚本。。有没有办法放大maxBuffer?请参阅我的代码:
thecaller: function(req, callback) {
const geoJSON = req.geoJSON;
const nameofinstance = req.name;
const Promise = require("bluebird");
const cmd = require('node-cmd');
const getAsync = Promise.promisify(cmd.get, { multiArgs: true, context: cmd });
getAsync(`python3 firstscript.py`)
.then(() => getAsync(`python3 secondscript.py`))
.then(callback(nameofplanung));
问题首先出现在“.then”而不是使用
节点cmd
您可以执行以下操作
您要设置的是maxBuffer
选项
略加修改的示例:
const { exec } = require('child_process');
const execAsync = function(cmd){ return new Promise((res,rej)=>{
exec(cmd,{maxBuffer:4*1024*1024}, (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
rej(err)
}
console.log(`stdout: ${stdout}`);
console.error(`stderr: ${stderr}`);
res(stdout);
});
})}
execAsync('ls').then(r=>...).catch(e=>...)
谢谢你的答复。在我编辑之后,这仍然有效吗?我不是在执行节点js中的命令,而是通过cmd访问的外部命令。是的,spawn/exec用于运行其他程序,比如python。如果您查看一下
node cmd
的源代码,它会在内部使用exec
。你也可以在上面设置maxBuffer
选项,exec(“cmd.exe”,{maxBuffer:8*1024*1024})
我测试了它,它适合我!我如何将它与getasync、bluebird和promise结合起来,就像我在代码片段中所做的那样?您可以手动promisify——就像我上面所做的那样。(编辑我的示例)