Short form: Were I to make a semi-educated guess, it would be this: You need to capture the output of both STDOUT and STDERR.
Long form:
In *nix environments, many programs write their normal output to Standard Output (known as STDOUT), but write warning and error messages to Standard Error (known as STDERR). When your 'traceroute' command fails, the output from the error is written on STDERR, as illustrated by the following (STDOUT is file handle 1, STDERR file handle 2):
# Test to an entry that does not exist in DNS
$ traceroute foo.aussiebb.com.au
foo.aussiebb.com.au: Name or service not known
Cannot handle "host" cmdline arg `foo.aussiebb.com.au' on position 1 (
+argc 1)
$
# Same test, with STDOUT directed to /dev/null (discard output to STDO
+UT)
$ traceroute foo.aussiebb.com.au 1>/dev/null
foo.aussiebb.com.au: Name or service not known
Cannot handle "host" cmdline arg `foo.aussiebb.com.au' on position 1 (
+argc 1)
$
# Same test, with STDERR directed to /dev/null (discard output to STDE
+RR)
$ traceroute foo.aussiebb.com.au 2>/dev/null
$
If you are using a *nix-y OS, you may be able to get what you expect by simply appending the string '2>&1' to the command (which in many shells redirects anything sent to STDERR to STDOUT). Alternately, if you use one of the IPC::Run* modules you may be able to capture the error output explicitly.
All that to say that in your example the 'open' line would be changed to read: open("runmain","$commands{$PROGRAM} $TARGET_HOST 2>&1 |");
(Although you might want to consider checking if the open failed or not.)
Hope that helps.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|