pike has asked for the wisdom of the Perl Monks concerning the following question:

Hi there,

I have a script which partitions a large set of files into sets of approx. equal (byte) size and then executes a command for each of the sets using system. The problem I have now is that sometimes even the subsets are so large that I exceed the max. number of arguments the shell supports. I'd like to change this, but I can't find out what the max number of arguments is! Is there any variable / function / module to get this information?

OK, so this is more of a shell question than a perl question, but anyway....

Thanks,

pike

P.S.: I have to keep track how many commands I submitted, so using  xargs is not an option...

Replies are listed 'Best First'.
Re: max number of arguments
by Zaxo (Archbishop) on Sep 05, 2002 at 09:02 UTC

    It may help to bypass the shell by calling system with list syntax:

    my $result = system '/path/to/program', $flags, @bigarray;
    You don't say what system call you're running, but it could have limits of its own. Check the return value to see what happened.

    After Compline,
    Zaxo

      I'm running RedHat linux - and I use bash as my logon shell. Is there any environment variable that contains the max length of the command line? Or any other way to get it?

      pike

Re: max number of arguments
by PodMaster (Abbot) on Sep 05, 2002 at 09:02 UTC
    You'd really need to consult your shell's documentation. There really isn't a limit on the number of arguments you can pass, but more the length. This isn't always easy to track down in documentation (especially if it isn't documented).

    I suggesting reading the arguments off of stdin, by simply fireing off a system(qw{ ./foo < foo.args })

    Either that or use something like DB_File, and pass arguments that way. You can keep things simple this way (simple enough)

    update:
    IIRC, there is also a module on cpan which would let you circumwent any shell argument size limits, but it may be just a figment of imagination (it might be Argv I was thinking off, but it doesn't matter, it appears Zaxo is correct).

    update:
    Great Zaxo, if that indeed is true ;)

    ____________________________________________________
    ** The Third rule of perl club is a statement of fact: pod is sexy.

Re: max number of arguments
by MZSanford (Curate) on Sep 05, 2002 at 15:41 UTC