最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Node.jschild_process throwing E2BIG - Stack Overflow

programmeradmin1浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 1

Try 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.

发布评论

评论列表(0)

  1. 暂无评论