Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: null output on program

by atcroft (Abbot)
on Nov 19, 2022 at 01:39 UTC ( [id://11148251]=note: print w/replies, xml ) Need Help??


in reply to null output on program

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11148251]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2025-12-06 18:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (85 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.