On Thu, Dec 26, 2013 at 5:34 PM, John W. Krahn <jwkr...@shaw.ca> wrote: > Kenneth Wolcott wrote: >> >> Hello; > > > Hello Kenneth, > > > >> I'm trying to obtain line-by-line output from a command pipe in perl. >> >> Unfortunately, I am firmly held to 5.8.8 version of perl on this >> specific machine :-( >> >> Apparently, creating an array for my command prevents me from >> including the final pipe symbol when trying to use the three-argument >> form of open when using an array for my command rather than a scalar. >> >> code snippet #1: >> my @cmd = ("make", "target_name", "2>&1"); >> open my $fh, @cmd, "|" or die "blah: $!\n"; fails, "Unknown open() mode >> '5'" >> >> code snippet #2: >> my @cmd = ("make", "target_name", "2>&1", "|"); >> open my $fh, @cmd or die "blah: $!\n"; fails, "Unknown open() mode '5'" > > > Those won't work because the second argument for open() has to be the mode > and it has to be a scalar value: > > $ perl -le'print prototype "CORE::open"' > *;$@ > > So the first example is: > > open my $fh, 3, "|" or ...; > > And the second example is: > > open my $fh, 4 or ...; > > Because an array in scalar context is the number of elements in the array. > > The correct syntax is: > > open my $fh, '-|', @cmd, or ...; > > But using a list instead of a string means that "2>&1" will be treated as a > text string and will not effect the STDERR stream. > > For STDERR redirection you need to run it through the shell by using a > string: > > open my $fh, 'make target_name 2>&1 |' or ...; > > > > > John > -- > Any intelligent fool can make things bigger and > more complex... It takes a touch of genius - > and a lot of courage to move in the opposite > direction. -- Albert Einstein
Hi John, Shawn and Shlomi; Thank you for your help. I am successfully running now! Thanks, Ken Wolcott -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/