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

Why won't the following work? I have also tried placing the shell command in quotes with a pipe "|" appended but that throws an exception. I would like to use Shell but if I can't for whatever reason I will resort to using the usual syntax for doing what I need to get done here (ie open(PID,"/usr/bin/ps args |") or....

#!/usr/local/bin/perl -w use strict; use Shell; . . . open(PID,ps("-u gvc")) # doesn't work. or die("Cannot open pipe for command: ps\n");
I am thinking this doesn't work because the Shell module doesn't pipe to the open() command. If this is the case, is there a way to make Shell.pm pipe?

----------
- Jim

Replies are listed 'Best First'.
Re: use'ing Shell and open()'ing a pipe - question
by VSarkiss (Monsignor) on Sep 28, 2001 at 02:59 UTC

    Well, part of the idea with Shell.pm is to avoid messing around with pipes altogether. (The rest of the idea seems to be Larry Wall goofing around -- see the pod.) You can write your example like this:

    use strict; use Shell; my @out = ps('-u', 'gvc');
    which will have the same result as if you'd opened a pipe to ps and slurped the contents into the @out array.

    HTH