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

You're most likely referring to psexec's STDERR. Try capturing it:
my $stderr; my $stdout = do { open(local *STDERR, ">", \$stderr) or die "Could not capture STDERR: $!"; qx(psexec \\\\server netstat -n); }; print "psexec stdout: $stdout\n"; print "-" x 60, "\n"; print "psexec stderr: $stderr\n";


It was eyepopslikeamosquito, not me :-)

Replies are listed 'Best First'.
Re^4: Convert from c# to Perl
by alwaysuseperl (Novice) on Aug 10, 2010 at 23:54 UTC

    Yeah, I was trying to get it to stop displaying the intro/header of psexec

    PsExec v1.96 - Execute processes remotely Copyright (C) 2001-2009 Mark Russinovich Sysinternals - www.sysinternals.com netstat exited on webd15 with error code 0.
      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.
Re^4: Convert from c# to Perl
by alwaysuseperl (Novice) on Aug 10, 2010 at 23:27 UTC

    I tried that, but it always has the header..

    PsExec v1.96 - Execute processes remotely Copyright (C) 2001-2009 Mark Russinovich Sysinternals - www.sysinternals.com