I am executing some cmd commands with getasync and it gives me this error:
Unhandled rejection RangeError [ERR_CHILD_PROCESS_STDIO_MAXBUFFER]: stderr maxBuffer length exceeded
The output is quite large, but I need it to debug the underlying python scripts.. Is there a way to enlarge the maxBuffer? See my code:
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));
The problem arises at the first ".then"
Instead of using node-cmd
you can do something like the following
https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options
What you want to set is the maxBuffer
option.
Example slightly modified:
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=>...)