Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Perhaps the way you were testing redirecting STDERR confused other responders.   (Then again you may have confused me - see davido's response.)   If you want to capture the STDERR output of another program that you start it gets differently complicated than just playing with the STDERR of your own program.

The various methods of TIE'ing STDERR won't work as they don't affect the STDERR filehandle (or more particularly the file descriptor ala fileno(STDERR)).   And you can play with open's using '>&STDERR' but that's still playing only with the running program.

On an *nix you could use fork and capturing output from child processes or any of the neat ways of doing the same using the open forms.   But since you mention ActiveState we should probably try for less complicated ways of doing things.   Would the code below work for you?   Namely, can you execute the program using the backtick operator?

# see qx/STRING/ in perlop, $? in perlvar, perlvar#error indicators my( @output, $status ); ($status, @output) = do_this_cmd( 'net use' ); ($status, @output) = do_this_cmd( 'net arf' ); ($status, @output) = do_this_cmd( 'netz arf' ); sub do_this_cmd { my $the_cmd = shift; my( @the_output, $error_status ); @the_output = qx($the_cmd 2>&1); $error_status = $? / 256; # Peek at arguments and returned values while debugging if(1){ printf "\nExecuted command '%s'\n", $the_cmd; printf "Process returned error status '%d'\n", $error_status if $error_status; if( @the_output ) { foreach (@the_output) { print " >>> ", $_; } } else { print "Process didn't return any output!\n"; } } ( $error_status, @the_output ); }
The outputs returned from the tests (on my system) were:

Executed command 'net use'
  >>> New connections will not be remembered.
  >>>
  >>>
  >>> Status       Local     Remote                    Network
  >>>
  >>> -------------------------------------------------------------------------------
  >>> Disconnected Z:        \\tls2ka\c$               Microsoft Windows Network
  >>> The command completed successfully.
  >>>

Executed command 'net arf'
Process returned error status '1'
  >>> The syntax of this command is:
  >>>
  >>>
  >>> NET [ ACCOUNTS | COMPUTER | CONFIG | CONTINUE | FILE | GROUP | HELP |
  >>>       HELPMSG | LOCALGROUP | NAME | PAUSE | PRINT | SEND | SESSION |
  >>>       SHARE | START | STATISTICS | STOP | TIME | USE | USER | VIEW ]
  >>>

Executed command 'netz arf'
Process returned error status '1'
  >>> 'netz' is not recognized as an internal or external command,
  >>> operable program or batch file.
I used the net command as it prints normal output to STDOUT (first test) but error output to STDERR (second test) as does the OS (third test).

In reply to Re: Best Way to Redirect STDERR to a Scalar by shenme
in thread Best Way to Redirect STDERR to a Scalar by Mr. Muskrat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (7)
    As of 2014-07-30 22:59 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (241 votes), past polls