CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Advanced:
On winblows: Process Status?



Oct 24, 2001, 3:06 PM

Post #1 of 3 (1598 views)
On winblows: Process Status? Can't Post

I'm using the Win32::Process::Create to initiate an outside process from my Tk gui. Now, if the user clicks on a particular button, I want the code to say:

if(processid is still running){ ... do this }
else{ ... do that }

However, all the methods that seem to make sense to me, aren't really working. Win32::Process::GetProcessID returns the PID of the process, BUT in checking the process id w/ this method after the process is dead, it still returns the same thing: the process id. In reality (read: my illusion) The process is done with... and I would think would return null or something. Is there a simple Stat function so I can see the stats of all the processes? Something like ps -ef on UNIX?

10 to 1 Marcus comes up w/ a reply first... Cool



Oct 24, 2001, 9:58 PM

Post #2 of 3 (1594 views)
Re: On winblows: Process Status? [In reply to] Can't Post

In Reply To
10 to 1 Marcus comes up w/ a reply first...

... Wink ... Laugh ... Cool ...

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,
) 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



Oct 24, 2001, 11:20 PM

Post #3 of 3 (1593 views)
Re: On winblows: Process Status? [In reply to] Can't Post

You amaze me marcus... your brain should be kept in a jar after your body dies.

Thanks again

*hmm* I'm pretty good with odds huh? I should go to the track some time.

Wow am I dense... I just realized that the jibberish at the bottom of your posts isn't there by accident. I would say that it's an understatement though. Smile

(This post was edited by Coderifous on Oct 24, 2001, 10:32 PM)


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives