Then try this...
###################################
use Win32::Process;
### build the command
my $server = "server";
my $tmpFile = "output.temp";
my $cmd = "uptime.exe \\\\$server \/a \/p:30";
print "calling $cmd...";
### save the standard output filehandle and open a new one
### reidrected to a file
open(THE_OLD_STDOUT, ">&STDOUT");
open( STDOUT, ">$tmpFile");
Win32::Process::Create( $oProcess,
"C:\\aaa_test\\uptime.exe",
$cmd,
1,
0,
"." );
### it always takes at least 5 seconds, so wait that long before we
### start to loop
sleep(5);
### set our quit flags to false (0)
$flgDone = 0;
$flgFailed = 0;
$i=0;
while ( !$flgDone && !$flgFailed )
{
### open the temp file to check it
open( FILE, "$tmpFile");
while (<FILE>)
{
### use a counter to quit if we wait too long
$i++;
### check for a match on the excpected last line
if ( /Total Application Failures/ )
{
$flgDone = 1;
}
### if we waited for 60 seconds, flag a quit
if ( $i > 60 )
{
$flgFailed = 1;
}
}
### close the temp file and wait to open it again
close(FILE);
sleep(1);
}
### retore the STDOUT and close the temp one
open (STDOUT, ">&THE_OLD_STDOUT") ;
close(THE_OLD_STDOUT);
### we did it, do whatever here (print for testing)
if ( $flgDone )
{
open( FILE, "$tmpFile");
while (<FILE>)
{
print $_;
}
close(FILE);
}
### the stupid thing hung again - KILL IT!!!!!!
if ( $flgFailed )
{
$oProcess->Kill( 0 );
}
###################################
-----Original Message-----
From: Philip Morley [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 29, 2002 11:20 AM
To: [EMAIL PROTECTED]
Subject: Getting the PID from system calls
Hi,
How do you get the PID of a background process started using system()?
I tried this:
my $Process = "C:\\foo\\foo.exe";
my $PID = system(1, $Process);
and from what I can tell, $PID actually stored the PID of a CMD.exe, and it
is that CMD.exe that launches $Process.
The O'Reilly book says "...in non-UNIX terms, it [system] runs the program
for you, and returns when it's done..." which I assume is what the CMD.exe
is doing.
PS. I am aware that Win32::Process does this, so no "...just use
Win32::Process instead..." responses please :-). I would happily use
Win32::Process if I could get it to redirect the output from the process.
(See my previous posting).
Thanks,
Phil Morley
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Visit our website at http://www.ubswarburg.com
This message contains confidential information and is intended only
for the individual named. If you are not the named addressee you
should not disseminate, distribute or copy this e-mail. Please
notify the sender immediately by e-mail if you have received this
e-mail by mistake and delete this e-mail from your system.
E-mail transmission cannot be guaranteed to be secure or error-free
as information could be intercepted, corrupted, lost, destroyed,
arrive late or incomplete, or contain viruses. The sender therefore
does not accept liability for any errors or omissions in the contents
of this message which arise as a result of e-mail transmission. If
verification is required please request a hard-copy version. This
message is provided for informational purposes and should not be
construed as a solicitation or offer to buy or sell any securities or
related financial instruments.
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs