0

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"

Leo
  • 222
  • 1
  • 4
  • 15

1 Answers1

1

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=>...)
Cody G
  • 8,368
  • 2
  • 35
  • 50
  • thx for the reply. is that still valid after the edit I did? I am not executing commands that are in node js, but external ones that I am accessing via the cmd. – Leo Jan 21 '20 at 15:39
  • 1
    Yes, spawn/exec are used to run other programs, like python. If you take a look at `node-cmd`'s source code it uses `exec` internally. You could set the `maxBuffer` option on that as well, `exec("cmd.exe",{maxBuffer:8*1024*1024})` – Cody G Jan 21 '20 at 15:47
  • I tested it and it works for me! how would I combine this with getasync, bluebird and promise as I have done it in my code snippet? – Leo Jan 21 '20 at 16:38
  • 1
    You can manually promisify --- like I did above. (edited my example) – Cody G Jan 21 '20 at 16:42