Getting STDERR from forked child processes?

Discussion in 'Perl Misc' started by Zbigniew Fiedorowicz, Feb 5, 2004.

  1. 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
    Zbigniew Fiedorowicz, Feb 5, 2004
    #1
    1. Advertising

  2. Zbigniew Fiedorowicz <> writes:

    > 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\\
    Brian McCauley, Feb 5, 2004
    #2
    1. Advertising

  3. Zbigniew Fiedorowicz <> wrote in message news:<bvto7c$9k$-state.edu>...
    > 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.
    Aaron Sherman, Feb 5, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeff Rodriguez
    Replies:
    23
    Views:
    1,111
    David Schwartz
    Dec 9, 2003
  2. kmkz

    Kill forked processes

    kmkz, Feb 26, 2006, in forum: Python
    Replies:
    4
    Views:
    415
  3. Pierre Morel
    Replies:
    5
    Views:
    121
    Pierre Morel
    Feb 17, 2010
  4. Peter
    Replies:
    1
    Views:
    167
    -berlin.de
    Jul 19, 2007
  5. Peter
    Replies:
    1
    Views:
    104
    Brian McCauley
    Jul 20, 2007
Loading...

Share This Page