HELP - with redirect of STDERR and STDOUT 
Author Message
 HELP - with redirect of STDERR and STDOUT

Hi,

I'm quite new to Perl, but in the current project I'm in, Perl is the
language to be used.
We're using Perl 5.xxx, so it's object oriented.

However, the code example I'm looking for is just common perl.

What I need to do is to execute a command, and redirect STDOUT to my own
filehandle,
and redirect SDTERR to another filehandle. As usual, I use
open(<my_handle>, "<command>|")
to redirect STDOUT to my filehandle. But what about STDERR for the
command I just exe-
cuted?

The definition of the function (method) should be:

(out, err, ret) = execute_mycmd($params),

Where:

out is the output printed on STDOUT
err is the output from STDERR
ret is a return code from the function

I would be very greatful for an example. I'm almost there, but I only
seems to turn off STDERR,
rather than redirect it.

Thanks in Advance,
/Richard Nilsson



Sat, 14 Jul 2001 03:00:00 GMT  
 HELP - with redirect of STDERR and STDOUT
[comp.lang.perl no longer exists]

Quote:

> What I need to do is to execute a command, and redirect STDOUT to my own
> filehandle, and redirect SDTERR to another filehandle.

This is an FAQ.  Please refer to perlfaq8.

<http://language.perl.com/newdocs/pod/perlfaq8.html#How_can_I_capture_...>

--


    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."



Sun, 15 Jul 2001 03:00:00 GMT  
 HELP - with redirect of STDERR and STDOUT

Quote:
> The definition of the function (method) should be:

> (out, err, ret) = execute_mycmd($params),

> Where:

> out is the output printed on STDOUT
> err is the output from STDERR
> ret is a return code from the function

I just checked if someone answered the question, and saw my own bug. The
usuage
of the function should of course be:

($out, $err, $ret) =  execute_mycmd($params);

But you already knew that...



Sun, 15 Jul 2001 03:00:00 GMT  
 HELP - with redirect of STDERR and STDOUT

Quote:

> [comp.lang.perl no longer exists]


> > What I need to do is to execute a command, and redirect STDOUT to my own
> > filehandle, and redirect SDTERR to another filehandle.

> This is an FAQ.  Please refer to perlfaq8.

> <http://language.perl.com/newdocs/pod/perlfaq8.html#How_can_I_capture_...>

> --


>     /                                  http://www.ziplink.net/~rjk/
>         "It's funny 'cause it's true ... and vice versa."

Thank you for the hint. I made almost as the FAQ said, but my thought was to avoid
temporary
files (in C, you can dup STDERR and STDOUT to it's respective pipe). I used:

--------
 open(STDERR, ">/tmp/stderr.out");    # Redirect STDERR

 close (STDERR);

# And then I open my stderr.out file, and just read it normally

--------

Which is basically the same as the FAQ suggests.

Thanks,

/Richard Nilsson



Sun, 15 Jul 2001 03:00:00 GMT  
 HELP - with redirect of STDERR and STDOUT
You could do is:

use IPC::Open3;

....


...

it will execute the "progname" and give three file handles. Write, read,
read_err.
If you don't need STDERR, you could use "open2" function instead.
But be aware, you might have to do some trick using "select" to avoid
IO Blocking.

Ji Lee

Quote:

> Hi,

> I'm quite new to Perl, but in the current project I'm in, Perl is the
> language to be used.
> We're using Perl 5.xxx, so it's object oriented.

> However, the code example I'm looking for is just common perl.

> What I need to do is to execute a command, and redirect STDOUT to my own
> filehandle,
> and redirect SDTERR to another filehandle. As usual, I use
> open(<my_handle>, "<command>|")
> to redirect STDOUT to my filehandle. But what about STDERR for the
> command I just exe-
> cuted?

> The definition of the function (method) should be:

> (out, err, ret) = execute_mycmd($params),

> Where:

> out is the output printed on STDOUT
> err is the output from STDERR
> ret is a return code from the function

> I would be very greatful for an example. I'm almost there, but I only
> seems to turn off STDERR,
> rather than redirect it.

> Thanks in Advance,
> /Richard Nilsson



Tue, 17 Jul 2001 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. HELP - with redirect of STDERR and STDOUT

2. Help redirect STDOUT, STDERR under NT !!!

3. redirect STDERR to STDOUT ?????

4. redirecting stderr and stdout

5. writing to terminal even with STDOUT and STDERR redirected

6. assigning STDERR whild redirecting STDOUT to a file

7. Problem with redirecting STDOUT and STDERR

8. How to redirect STDOUT,STDERR and keep the message order

9. Redirect stderr to stdout w/ Perl under Unix?

10. Redirecting STDERR to STDOUT (on NT)

11. need to redirect STDOUT and STDERR

12. Redirecting stdout/stderr from a call to system()

 

 
Powered by phpBB® Forum Software