I have a fairly simple C++ program which only takes one argument that is a Base64 encoded string. I can call the program.
I am now trying to call this program using Node.js' child_process.spawn(), but it is throwing an "E2BIG" error when I pass in the same Base64 string.
The Base64 string I am testing with is 305016 bytes in length.
Running getconf ARG_MAX
on my Linux box returns 2097152.
Why does child_process throw the error?
I have a fairly simple C++ program which only takes one argument that is a Base64 encoded string. I can call the program.
I am now trying to call this program using Node.js' child_process.spawn(), but it is throwing an "E2BIG" error when I pass in the same Base64 string.
The Base64 string I am testing with is 305016 bytes in length.
Running getconf ARG_MAX
on my Linux box returns 2097152.
Why does child_process throw the error?
Share Improve this question edited Jul 12, 2023 at 14:37 Peter Mortensen 31.6k22 gold badges110 silver badges133 bronze badges asked Mar 27, 2016 at 19:34 Jonathan SmithJonathan Smith 2,5991 gold badge37 silver badges67 bronze badges 4-
Have you seen What defines the maximum size for a mand single argument? on unix.SO? It mentions
MAX_ARG_STRLEN
as the maximum length of a string argument. – traktor Commented Mar 27, 2016 at 21:59 - 1 Thats useful information to know, but why would it work when running from the mand line, but not work using child_process.spawn()? – Jonathan Smith Commented Mar 28, 2016 at 10:30
-
1
let child = require('child_process').spawn('myprogram'); child.stdin.write(largeBase64String); child.stdin.end();
this code is not working? – Ali Reza Riahi Commented Jul 12, 2023 at 8:25 - @AliRezaRiahi an argument is ostensibly a string passed in on the mand line, whereas what you are suggesting is to provide input to the program via stdin, that's a different mechanism, and the asker was likely running into mand line argument length limitations, whereas stdin is unlimited. So yes, it's a workaround and ultimately the better approach for large amounts of data, but the question is valid as is and is asking for the reason, not a workaround. – Wyck Commented Jul 12, 2023 at 14:47
1 Answer
Reset to default 1Try to strace it to see if Node.js is making the system call or not - i.e., check is it an internal Node.js limitation or is it the Linux system which is rejecting it.
The strcpy
used by libuv
in Node.js can return E2BIG
.