Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^5: Convert from c# to Perl

by repellent (Priest)
on Aug 12, 2010 at 06:30 UTC ( [id://854592]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Convert from c# to Perl
in thread Convert from c# to Perl

According to online sources, it seems that psexec sends its output to stderr. This ought to work:
use File::Temp qw(tempfile); my $stderr_fh = tempfile(); my $stdout = do { open(*STDERR, ">&", $stderr_fh) or die "Could not capture STDERR: $!"; qx(psexec \\\\server netstat -n); }; seek($stderr_fh, 0, 0); my $stderr = do { local $/; <$stderr_fh> }; print "psexec stdout: $stdout\n"; print "-" x 60, "\n"; print "psexec stderr: $stderr\n";

My previous code did not work for a couple of reasons:
  • The ">", \$stderr form of open failed on Win32 for some reason. Worked around using a temp file.
  • Can't localize *STDERR.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2024-04-16 19:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found