in reply to Re: Re: Capturing STDERR with -
in thread Capturing STDERR with -
Try it again. I modified your 'exec' block to look like this:
open(STDERR, ">&STDOUT") if $redirect_stderr; exec("/usr/bin/nslookup", "-q=$query_type", $input, $nameserver) or die "exec: $!";
I also took out the 'splice' and ran your function like this:
print "Without:\n"; print "| $_\n" foreach nslookup('test', 'A'); print "\n"; $redirect_stderr++; print "With:\n"; print "| $_\n" foreach nslookup('test', 'A');
My output was this:
Without: Note: nslookup is deprecated and may be removed from future releases. Consider using the `dig' or `host' programs instead. Run nslookup wit +h the `-sil[ent]' option to prevent this message from appearing. | *** Invalid option: q=A | Server: ns.intranet | Address: 10.0.0.1#53 | | ** server can't find test: NXDOMAIN With: | Note: nslookup is deprecated and may be removed from future release +s. | Consider using the `dig' or `host' programs instead. Run nslookup w +ith | the `-sil[ent]' option to prevent this message from appearing. | *** Invalid option: q=A | Server: ns.intranet | Address: 10.0.0.1#53 | | ** server can't find test: NXDOMAIN
The 'deprecated' warning is sent out via STDERR, which is being captured in the second run. So it seems to be working perfectly for me.
Note that even though you're doing an exec, file descriptors 0, 1 and 2 (STDIN, STDOUT and STDERR) are inherited by the child process. (This is configurable with $^F; see perlvar.) Since all you're doing here is 'dup'ing 2 to be the same as 1, all 3 get passed as-is and work as you expect.
On a lesser note, if it is this warning you're trying to omit, is there any reason you're still coding your script to use 'nslookup' instead of, as it recommends, 'dig' or 'host'? The 'dig' tool is pretty easily parseable and I think intended for applications like this moreso than nslookup was. Just a thought..
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: Capturing STDERR with -
by DrManhattan (Chaplain) on Dec 07, 2001 at 18:59 UTC | |
by Fastolfe (Vicar) on Dec 08, 2001 at 03:00 UTC |