I hope I am not wrong in creating a new thread on this. I had asked another wuestion yesterday that was somewhat related. I am using a variation of the code found here Win32::KillProcess (see my code below) to kick off a remote exe. Does anyone know if it is possible to capture the output from the remote exe or wait for the remote exe to return a spacific exit code before considering it started? As always any help is appreciated.
use strict; use Win32::OLE::Variant; my ($opts_ret, $svr, $help_var, $usr, $pwd, $exe); use Getopt::Long qw(:config no_ignore_case); $opts_ret = Getopt::Long::GetOptions( 'server=s' => \$svr, 'username=s' => \$usr, 'password=s' => \$pwd, 'command=s' => \$exe, 'help!' => \$help_var); if (($help_var) | ($ARGV[0] =~ /\?/)){ &help; exit 0; } elsif(!$exe){ print "Syntax Error: command is required\n\n"; &help; exit 0; } my $Con = connectServer( $svr, $usr, $pwd ); print "STARTING EXE\n"; my $pid = startProcess( $Con, $exe, "C:\\temp"); print "PID IS $pid\n"; sub connectServer { my ( $svr, $usr, $pwd ) = @_; $svr ||= '.'; # just in cass I want to use args and run it on loc +alhost my $locator = Win32::OLE->new("WbemScripting.SWbemLocator") or die "Can't access WMI on local machine.", Win32::OLE->LastE +rror; my $Conn = $locator->ConnectServer($svr, "root/cimv2", $usr, $pwd) + or die "Can't access WMI on remote machine $svr: ", Win32: +:OLE->LastError; return $Conn; } sub startProcess { my ( $Conn, $exe, $startdir ) = @_; my $startClass = $Conn->Get("Win32_Process") or die Win32::OLE->La +stError; my $startConfig = $startClass->SpawnInstance_ ; my $pid = Variant(VT_I4|VT_BYREF, 0); my $retval = $startClass->Create( $exe, $startdir, undef, $pid ); if ( 0 == $retval ) { return $pid; } else { die "Could not start $exe errcode: " . decode_error($retval); } } sub decode_error { my %h = ( 1 => "Not Supported", 2 => "Access Denied", 8 => "Unknown Failure", 9 => "Path Not Found", ); return $h{$_[0]} ? $h{$_[0]} : "Can't resolve error code $_[0]"; } sub help{ print " Usage: rmtstart [-s <servername>] [ -u <username | <domain>\username +] [ -p <password> ] -c <command> OPTIONS: -s Defines server on which to run command. This is not a required + argument, if not supplied the command will be run on the local computer. -u Defines user name or domain\username to run the command as. If + not supplied currently logged on user on local computer will be used. -p Defines password of user running command. -c Defines Command to be run. Arguments may be passed and spaces +may exist in pathname but in both of these cases you must enclose the command in quotes. "; }

In reply to capture output from remote process created via wmi and OLE by boat73

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.