markcsmith has asked for the wisdom of the Perl Monks concerning the following question:

I would like to catch EVERYTHING that a program barfs out for output. Whenever I try either of the following:

open OPUT, "command|"; @read = <OPUT>; close OPUT;

@read = `command`;

It works fine until there's a message that "appears" to be sent to STDERR instead of STDOUT. How do I not let anything go by? Whenever something escapes, the shell suspends my program b/c I stuck it in the background :(


Thanks!
Mark

Replies are listed 'Best First'.
Re: being oppresive to output
by fglock (Vicar) on Oct 30, 2002 at 21:24 UTC

    You can finish your command line with a redirect-stderr-to-stdout:

    command 2>&1

    Does not work in windows;
    See:  man bash for more info.
    See also: IPC::Open3 and perlipc.

    update: it doesn't work in WinNT (tested)

      You can also do this in your program:
      open STDERR, ">&STDOUT" or die "Cannot dupe STDOUT: $!\n";

      Depends on the version of Windows. The 2>&1 works just fine in my Win2k. And I think it would work fine in WinNT as well.

      Jenda

      "comand 2>&1" also won't work if the program interacts directly with /dev/tty, but it's what I would try first.