Too many arguments for open at /home/vpoint/testing.pl line 10, near "
+'/bin/bash' )
"
Execution of /home/vpoint/testing.pl aborted due to compilation errors
+.
I was trying to use the code exactly as you posted it. The only thing I removed was use warnings. The OS I am using is
SunOS ferb 5.8 Generic_117350-21 sun4u sparc SUNW,Ultra-80
This is the perl version in case it helps.
perl, version 5.005_03 built for sun4-solari | [reply] [d/l] [select] |
perl, version 5.005_03 built for sun4-solari
That explains it. Your ancient SunOS system is using an ancient Perl release. The code I posted requires Perl 5.8 or later, due to its use of the "3-argument" form of the open call, which wasn't available in perl 5.5 (which is what you have in this case). Sorry, I just assumed that no one would still be using such an old version of Perl.
To fix that, use the "2-argument" form for the open call -- like this:
#!/usr/bin/perl
use strict;
use warnings;
my @cmd_list = ( 'echo 1', 'echo 2', 'echo 3', 'echo 4' );
$|++; # turn off buffering
my $shpid = open( my $sh, '|/bin/bash' )
or die "Can't open a shell process: $!\n";
for my $cmd ( @cmd_list ) {
print $sh "$cmd\n";
}
print $sh "exit\n";
close $sh;
waitpid( $shpid, 0 );
print "Shell's all done. Moving right along...\n";
That approach will also work with more recent versions of perl. | [reply] [d/l] |