in reply to invoke shell with `` failed

Are you maybe leaving behind stuff in the environment upon every iteration?  On most Unixes, the command line arguments share a fixed space with the process' environment.

For example, the following would reproduce the issue (tested on Linux):

#!/usr/bin/perl for (1..10) { $ENV{JUNK} .= "ABC" x 5000; my $begin_load = `cat /proc/loadavg`; warn "cat failed: $!" if $?; print $begin_load; } __END__ 0.56 0.43 0.25 1/219 27522 0.56 0.43 0.25 3/219 27523 0.56 0.43 0.25 2/219 27524 0.56 0.43 0.25 2/219 27525 0.56 0.43 0.25 2/219 27526 0.56 0.43 0.25 2/219 27527 0.56 0.43 0.25 3/219 27528 0.56 0.43 0.25 3/219 27529 cat failed: Argument list too long at ./757540.pl line 7. cat failed: Argument list too long at ./757540.pl line 7.

Replies are listed 'Best First'.
Re^2: invoke shell with `` failed
by jiangliguo (Initiate) on Apr 16, 2009 at 09:56 UTC
    Really appreciate for your help,it should be the real reason. Is there any good method to avoid such situation since each iteration env is not the same.