Getting STDERR from forked child processes?

  • Thread starter Zbigniew Fiedorowicz
  • Start date
Z

Zbigniew Fiedorowicz

How can I catch error messages from external programs forked
from a Perl cgi process? I can of course read from the web
server error log, but I am worried that I might be getting
the wrong error messages from some other web server process
which is running concurrently.

TIA,
Zig Fiedorowicz
 
B

Brian McCauley

Zbigniew Fiedorowicz said:
How can I catch error messages from external programs forked
from a Perl cgi process?

Can you explain how your question differs from the FAQ: "How can I
capture STDERR from an external command?"

Note: the FAQ doesn't mention you can also do fork/reopen STDOUT/exec
as you would in C.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
 
A

Aaron Sherman

Zbigniew Fiedorowicz said:
How can I catch error messages from external programs forked
from a Perl cgi process? I can of course read from the web
server error log, but I am worried that I might be getting
the wrong error messages from some other web server process
which is running concurrently.

Do you mean fork()ed or do you mean a truely external program (e.g.
using system, qx{} or fork()/exec)?

Let's use qx{} (aka ``) as a simple example:

method a:

$result_plus_err = qx{/usr/bin/do_stuff 2>&1};

method b:

use IPC::Open3 qw(open3);
use IO::Select;
open3(\*WTRFH, \*RDRFH, \*ERRFH, "/usr/bin/do_stuff");
close WTRFH;
my $r = IO::Select->new(\*RDRFH,\*ERRFH);

and from there you can call the "can_read" method on $r and continue
along your happy way.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top