I recently upgraded one of my Win2K servers to Win2K3. After the upgrade, the Win32::Process module appears to be slightly broken in that it does not properly state the current process state. I have posted the issue with active state (who as far as I know supplied this module) but until there is a fix, I need to find another solution for tracking process state. The following example demostrates the issue:
my($exitcode,$junk,$process,$process2,$process3);
use Win32::Process;
#create a notepad process
Win32::Process::Create(
$process,
"c:\\winnt\\system32\\notepad.exe",
"",
0,
NORMAL_PRIORITY_CLASS,
'.',
) or die "Could not start process\n";
#get the processid
$procid=$process->GetProcessID();
print "PROCID: $procid\n";
#open the procid and get the exit code
if(Win32::Process::Open($process2,$procid,0)==1){
Win32::Process::Open($process2,$procid,0);
$exit=$process2->GetExitCode( $exitcode );
print "EXIT for PROCID-$procid: $exit\n";
print "Enter to continue\n";
}else{
print "ProcessID $procid not running\n";
}
$junk=<STDIN>;
#ok, kill the process
$process->Kill( $exitcode );
print "$procid Process Killed\n";
print "Enter to continue\n";
$junk=<STDIN>;
#now get the procid and exit code again
if(Win32::Process::Open($process3,$procid,0)==1){
Win32::Process::Open($process3,$procid,0);
$exit=$process3->GetExitCode( $exitcode );
print "EXIT for PROCID-$procid: $exit\n";
}else{
print "ProcessID $procid not running\n";
}
exit;
Under Win2K, this should show the following after opening and closing notepad:
PROCID: 1016
EXIT for PROCID-1016: 1
Enter to continue
1016 Process Killed
Enter to continue
ProcessID 1016 not running
However, on my Win2k3 systems, it is doing the following:
PROCID: 1980
EXIT for PROCID-1980: 1
Enter to continue
1980 Process Killed
Enter to continue
EXIT for PROCID-1980: 1
Even though it *is* properly killing the notepad processID, it still seems to think it is openable with the module.
Now, all I need to do is have the script kick off a process that will eventually end on its own (it does not need killed) and check in to see if that process is still running every 10-15 seconds. (ie, all I really want is to know when
Win32::Process::Open($process3,$procid,0)==0 ). I do not have a way to have that external process mark a file while it's running, so that is not an option. Is there another module I can use to check for a running process by process ID under Win32?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.