
mhx
Enthusiast
Oct 24, 2001, 9:58 PM
Post #2 of 3
(811 views)
|
|
Re: On winblows: Process Status?
[In reply to]
|
Can't Post
|
|
10 to 1 Marcus comes up w/ a reply first... ... ... ... ... So I guess you only want to know about whether the process is still running or it has finished. You can use the GetExitCode method of Win32::Process. It maps to Window's GetExitCodeProcess API call (at least I assume that, I haven't looked at the source). This will set the variable you supplied to the exit code of the process if it has yet finished or to STILL_ACTIVE if the process is still running. Unfortunately, STILL_ACTIVE isn't exported by Win32::Process. If you have a Windows C compiler, you can have a look at the include files winbase.h and winnt.h. In these files, STILL_ACTIVE is defined to be STATUS_PENDING and STATUS_PENDING to be 0x00000103. So as long as Microsoft doesn't change their include files (which I don't think will happen), you can assume 259 to be the same as STILL_ACTIVE. With that in mind, it's not too hard to do what you want:
#!/bin/perl -w use strict; use Win32::Process; use constant STILL_ACTIVE => 259; my( $p, $x ); Win32::Process::Create( $p, 'c:\windows\notepad.exe', 'notepad', 0, NORMAL_PRIORITY_CLASS, '.' ) or die ErrorReport(); while( 1 ) { $p->GetExitCode( $x ); if( $x == STILL_ACTIVE ) { print "Process is still running...\n"; } else { print "Process has exited with code [$x]\n"; } sleep 1; } Hope it helps. -- Marcus
s$$ab21b8d15c3d97bd6317286d$;$"=547269736;split'i',join$,,map{chr(($*+= ($">>=1)&1?-hex:hex)+0140)}/./g;$"=chr$";s;.;\u$&;for@_[0,2];print"@_,"
|