0
votes

one case: I wrote script on tsch that invoke other script on python. When I invoke python script from cmd , it is OK. When I invoke test script on tsch then I get error: Argument list too long

Another case:

git grep -e "alex" -- `git ls-files | grep -v 'bin'`

I also get error: Argument list too long. What can problem and How to solve it ?

2
You ask "what can be the problem"? Well, probably the argument list is too long, isn't it? Did you check its length? Every shell has limits. - arkascha
How can I check it ? When I run from command line, I have not problem. @arkascha - user8588509
Well, how is it called? You could redirect the argument list into a file for example. - arkascha
script.py > file @arkascha - user8588509
No, that redirects the output of the script. The error message is about the input to some process. Either the script itself or something the script calls internally. - arkascha

2 Answers

0
votes

Updated Answer

I'm not familiar with the specific git commands you are using and you don't seem to be replying sensibly to the questions in the comments either. I guess you probably want something like this though:

git ls-files | grep -v 'bin' | xargs -L 128 git grep -e "alex" --

Original Answer

The classic way to solve "error: Argument list too long" is with xargs. It can be used to repeatedly call a script whose name you provide, or echo if you don't provide one, with a limited number of arguments till the arguments are all consumed.

So, imagine you have a million files in a directory, then ls * will fail, however a simple ls will work. So, we can put that to use with:

ls | xargs -L 128

which will call echo (because we didn't provide a utility name) repeatedly with 128 filenames at a time till all are echoed.

So, you could do:

ls | xargs -L 128 yourScript.py

to call your Python script repeatedly with 128 filenames at a time. Of course you may be doing something completely different and incompatible with this technique but your answers are not very helpful so far...

0
votes

for somebody comes here who need to do something like this:

./shell_script.sh param1

but it raises error Argument list too long from shell script of param1. I just run into this, and fix it by a workaround of using the shell variable.

# calling the PARAM1 instead of $1 in code of shell_script.sh
export PARAM1=param1 ./shell_script.sh 

an example of a ruby version of transferring string to nodejs:

ENV["PARAM1"]="a_bunch_of_test_string_as_longer_as_you_can"
`node node_script.sh`
var param1 = process.env.PARAM1;
console.log(param1);