ccarden has asked for the wisdom of the Perl Monks concerning the following question:
I don't quite seem to understand how redirection works. I know that 2>&1 feeds stderr into stdout. I think that adding a pipe after that (2>&1|) pipes the combined output back to the file handle (yes/no?). But how do I test failure of the external command? Seems to me that one would not want to combine stderr with stdout in that case, que no?
I'm not convinced that this is the best way to do things. For one thing, I'm don't really dig using sed or any other system command, if I don't have to. For another, I've seen examples of code with die if the open fails:my $cmd = 'someProcess.pl -parm val'; open (CMD, "($cmd | sed 's/^/STDOUT:/') 2>&1|"); while (<CMD>;) { if (!s/^STDOUT://) { exitSub(2," Process failed: $_"); } else { # Split the output of the process into ret chomp; @ret = split; } } close (CMD);
open (CMD, "($cmd | sed 's/^/STDOUT:/') 2>&1|") or die $!;
If someone could help me understand what is going on, I would appreciate it. I'd rather learn how to fish than be given one.
Thanks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Error trapping while capturing stdout
by Random_Walk (Prior) on Sep 14, 2004 at 14:37 UTC | |
by ccarden (Monk) on Sep 14, 2004 at 15:35 UTC | |
by Random_Walk (Prior) on Sep 14, 2004 at 16:15 UTC | |
|
Re: Error trapping while capturing stdout
by ikegami (Patriarch) on Sep 14, 2004 at 14:23 UTC | |
by ccarden (Monk) on Sep 14, 2004 at 16:03 UTC | |
by ikegami (Patriarch) on Sep 14, 2004 at 16:09 UTC | |
|
Re: Error trapping while capturing stdout
by coreolyn (Parson) on Sep 14, 2004 at 16:17 UTC | |
by ccarden (Monk) on Nov 09, 2004 at 21:31 UTC |