Syntactic Confectionery Delight | |
PerlMonks |
Error trapping while capturing stdoutby ccarden (Monk) |
on Sep 14, 2004 at 13:51 UTC ( [id://390840]=perlquestion: print w/replies, xml ) | Need Help?? |
ccarden has asked for the wisdom of the Perl Monks concerning the following question:
Hi, folks,
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?
Here is an example of what I'm currently doing:
Currently, I find that if my external process fails or gives warnings, the calling code (first example) lets it fall through. A recent example was when I added use warn to the external script and it started spewing out some warnings. This caused the calling script to fail because of unexpected text in the resulting capture of stdout. If I recall correctly, warnings go to stdout, not stderr, right? How would you handle warnings, then?
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:
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.
Back to
Seekers of Perl Wisdom
|
|