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:
That approach will also work with more recent versions of perl.#!/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";
In reply to Re^5: Multiple commands with one system call
by graff
in thread Multiple commands with one system call
by renzosilv
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |