open COMMAND with a pipe 
Author Message
 open COMMAND with a pipe

So I am trying to do something like this:

open COMMAND, "make -f Makefile |";
while(<COMMAND>)
{
  print;

Quote:
}

close COMMAND;

But now I need to check the return value of 'make.'   I need to know
if it was successful or if it failed.  But I don't know how to do
this.  I tried combinations of '$?' but that doesn't seem to work.
Ideas?  Thanks.

-j



Mon, 19 Sep 2005 18:28:54 GMT  
 open COMMAND with a pipe

Quote:

> So I am trying to do something like this:

> open COMMAND, "make -f Makefile |";
> while(<COMMAND>)
> {
>   print;
> }

> close COMMAND;

> But now I need to check the return value of 'make.'   I need to know
> if it was successful or if it failed.  But I don't know how to do
> this.  I tried combinations of '$?' but that doesn't seem to work.
> Ideas?  Thanks.

> -j

Easier to use system.

system("/usr/bin/make -f ./Makefile") == 0 or die "make failed!";

If you need the error, you could capture STDERR.

 From perlfaq8:

To capture a command's STDERR but discard its STDOUT:

     $output = `cmd 2>&1 1>/dev/null`;           # either with backticks
     $pid = open(PH, "cmd 2>&1 1>/dev/null |");  # or with an open pipe
     while (<PH>) { }                            #    plus a read



Mon, 19 Sep 2005 19:20:23 GMT  
 open COMMAND with a pipe

Quote:

> open COMMAND, "make -f Makefile |";
> while(<COMMAND>)
> {
>   print;
> }
> close COMMAND;
> But now I need to check the return value of 'make.'   I need to know
> if it was successful or if it failed.

perldoc -f close

    If the file handle came from a piped open "close" will additionally
    return false if one of the other system calls involved fails or if
    the program exits with non-zero status.  (If the only problem was
    that the program exited non-zero "$!" will be set to "0".)
    [...]
    and implicitly puts the exit status value of that command into "$?".

Chris

until$s[$i];$c=$s[$i];print$c;undef$s[$i];$i=($i+(ord$c))%$l}



Tue, 20 Sep 2005 12:13:45 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. piping command output to open()

2. Opening a pipe to a command

3. open a piped command including stderr

4. open command that pipes both in and out

5. unix command displayed when using PIPES with open.

6. Killing a pipe-opened command in Win32?

7. Piping in stderr when creating a pipe with the open call

8. PERLFUNC: open - open a file, pipe, or descriptor

9. PERLFUNC: open - open a file, pipe, or descriptor

10. Perl's open() pukes when trying to open a read-type pipe

11. HELP: Piping shell command into perl command?

12. open(PIPE,"| command |") -- pipe & fork?

 

 
Powered by phpBB® Forum Software