Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

THANKS TO ALL: Passing huge args to system call

by bubulik (Novice)
on Aug 05, 2004 at 19:00 UTC ( [id://380351]=perlquestion: print w/replies, xml ) Need Help??

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

I am making a system call with a huge sized argument. Here is the call:
!system ("perl", $perl_file, $comp, $warn_list_arg); or die "Program +exit";
where: $warn_list_arg at times contains about 8000+ strings, each string consisting about 60+ chars. This arg is delimited such that the invoked Perl process can unmarshall these args.

For a small sized $warn_list_arg, the call executes OK. For larger sizes such as 8000+ strings, it fails. Here are some specs:

Exit value: 255 ($! >> 8)
Signal num: 0 ($! & 127)
Core dump: 0 ($! & 128)

Is there a size limit on the buffer containing the args? How might I be able to pass such a big arg?

BTW: i resorted to this method of passing args since passing an array/list to the system call failed to pass the args on to the invoked process. Or is there some way to pass arrays in a system call?

Thnx for any suggestion/help.

Thanks to all u folks for yr replies: sleepingsquirrel nothingmuch davido eclark ccn Creating the process via a filehandle was the trick for me! BBK

Edit by castaway, reinserted original question

Replies are listed 'Best First'.
Re: Passing huge args to system call
by ccn (Vicar) on Aug 05, 2004 at 19:06 UTC

    You can pass your $warn_list_arg to STDIN of your $perl_file

    open(SCRIPT, "| perl $perl_file $comp") or die "can't run $perl_file: $!"; print SCRIPT $warn_list_arg; close(SCRIPT) or die "can't close $perl_file: $!";

    see perlopentut, open

Re: Passing huge args to system call
by davido (Cardinal) on Aug 05, 2004 at 19:10 UTC

    Maybe you could open a pipe to the second process, instead of invoking a system call to it. Or, save the large array as a file, and pass the filename to the second process.

    Also, you've got a problem with the snippet you posted. The semicolon after the system call terminates the sentence, so to speak. So the "or die..." portion is its own separate statement. You meant to say:

    ! system ( "perl", $perl_file, $comp, $warn_list_arg) or die "Program +exit";

    As for how to open a pipe, see perlopen and perlopentut.


    Dave

Re: Passing huge args to system call
by eclark (Scribe) on Aug 05, 2004 at 19:06 UTC

    I dont know what the problem is, but have you considered passing $warn_list_arg as lines to STDIN?

    Such as:

    open FH, "|perl $perl_file $comp"); for (@warn_list) { print FH $_ . "\n"; } close FH;

    You'll have to modify $perl_file to read them from <STDIN> instead of @ARGV.

Re: Passing huge args to system call
by nothingmuch (Priest) on Aug 05, 2004 at 19:45 UTC
    Afaik no kernel but HURD does not impose a software level hard limit on the number of arguments. On darwin, IIRC, the buffer is at most 64K in length. I think Linux is in the same ballpark.

    These may be defaults to kernel params, or even sysctlable, but there is a limit, and it isn't very big. I would suggest following on the advice that others gave you, to open a pipe.

    I would do it with a pipe to self, or by piping to $^X:

    defined(my $pid = open my $child, "|-") or die "$!"; if ($pid){ # parent print $child "$args"; } else { #child my $args = <STDIN>; } # or for an exec, at least run $^X instead of "perl": open my $child, "|$^X", $scriptfile;
    -nuffin
    zz zZ Z Z #!perl
Re: THANKS TO ALL: Passing huge args to system call
by saberworks (Curate) on Aug 06, 2004 at 00:13 UTC
    You really shouldn't edit your comment to remove the question after it's answered, it can't help anyone that way.
Re: Passing huge args to system call
by sleepingsquirrel (Chaplain) on Aug 05, 2004 at 20:19 UTC
    Probably not what you're looking for, but as long as you're calling perl (system "perl"...), why not...
    @ARGV=split /\s+/, $warn_list_arg; unshift @ARGV, $comp; do $perl_file or die "Program Exit: $!\n";


    -- All code is 100% tested and functional unless otherwise noted.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://380351]
Approved by ccn
Front-paged by ccn
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-16 22:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found