Is there an easy way I can capture STDERR from the child process as well as STDOUT? As I see it, these are my options:sub nslookup { my ($input, $query_type) = @_; # Fork a child process to exec nslookup, # and capture its output if (open(NSLOOKUP, "-|")) { # Parent process. Read output from child. my @output = <NSLOOKUP>; splice(@output, 0, 3); return @output; } else { # Child process. exec() nslookup exec("/usr/sbin/nslookup", "-q=$query_type", $input, $nameserver); } }
1) Rewrite with backticks:
I don't like this because it means I have to send user input into backticks. My whole point in open()ing "-|" was to feed the args into exec() as an array. I'm already scrubbing the input anyway, but better safe than sorry, eh?@output = `/usr/sbin/nslookup -q=$query_type $input $nameserver 2>&1`;
2) Rewrite using open3(). open3() looks evil.
3) Rewrite using Net::DNS instead of executing nslookup. This is the cleanest, most portable option, but it will take more time than this script is worth because I'll have to completely rewrite the output handling.
-Matt
In reply to Capturing STDERR with - by DrManhattan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |