Piping STDERR 
Author Message
 Piping STDERR

Hi. I'm trying to write a perl script, and learning perl as I go.
I'm trying to read the STDERR output from a command, and perform some
actions depending on what the output is.
In this case, I'm calling 'identify' from the Image Magick package, which prints
the image information to STDERR (size, type, etc).
I'm opening a pipe to read the info, but can't seem to read any STDERR data out. It looks like
pipes can only handle STDOUT, not STDERR.

e.g
        open (PIPE, "identify image | ") || die ...
        while (<PIPE>)
                extract the correct fields.

        close(<PIPE>);

This will read the STDOUT, but I can't seem to make it read STDERR (either both
STDERR and STDOUT, or just STDERR). This is no STDOUT produced at all, so
the while (<PIPE>) loop simpyl drops out, and the STDERR gets printed to the screen.
Using
        open (PIPE, "identify image |& ") || die
causes open to fail.

Ant hints/tips/suggestions will be greatly appreaciated.

I'd prefer an email reply, and a posted one will do.
Thanks,

                Ash.

--

CSIRO Div of Manufacturing Tech,      Phone: +61 3 662 7799
Locked Bag No. 9,                     Fax:   +61 3 662 7851
Preston, Vic, 3072, Australia.



Fri, 09 May 1997 07:18:44 GMT  
 Piping STDERR

|>
|> Hi. I'm trying to write a perl script, and learning perl as I go.
|> I'm trying to read the STDERR output from a command, and perform some
|> actions depending on what the output is.
|> In this case, I'm calling 'identify' from the Image Magick package, which prints
|> the image information to STDERR (size, type, etc).
|> I'm opening a pipe to read the info, but can't seem to read any STDERR data out. It looks like
|> pipes can only handle STDOUT, not STDERR.
|>
|> e.g
|>   open (PIPE, "identify image | ") || die ...
|>   while (<PIPE>)
|>           extract the correct fields.
|>
|>   close(<PIPE>);
|>
|> This will read the STDOUT, but I can't seem to make it read STDERR (either both
|> STDERR and STDOUT, or just STDERR). This is no STDOUT produced at all, so
|> the while (<PIPE>) loop simpyl drops out, and the STDERR gets printed to the screen.
|> Using
|>   open (PIPE, "identify image |& ") || die
|> causes open to fail.
|>
|> Ant hints/tips/suggestions will be greatly appreaciated.
|>
|> I'd prefer an email reply, and a posted one will do.
|> Thanks,
|>
|>
|>           Ash.
|>
|>
|>
|> --

|> CSIRO Div of Manufacturing Tech,      Phone: +61 3 662 7799
|> Locked Bag No. 9,                     Fax:   +61 3 662 7851
|> Preston, Vic, 3072, Australia.

That'll teach me to look at the FAQ!!!
I've found the answer.
Simply do :-
        open (PIPE, "identify image 2>&1 | " ) || die ...

Just one of the sh incantations I didn't try...

Ciao for now.

                        Ash.

--

CSIRO Div of Manufacturing Tech,      Phone: +61 3 662 7799
Locked Bag No. 9,                     Fax:   +61 3 662 7851
Preston, Vic, 3072, Australia.



Fri, 09 May 1997 08:46:20 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. pipe STDERR

2. pipe STDERR

3. Piping STDERR to /dev/null when using system()

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

5. reading stdout/stderr using pipes

6. "open" pipe with stderr

7. pipes and STDERR

8. Directing stderr and stdout to a pipe

9. open a piped command including stderr

10. Distinguishing stdout and stderr on a pipe

11. Directing stderr when opening a pipe?

12. sending stdout and stderr to a pipe in perl

 

 
Powered by phpBB® Forum Software