Proc::Simple - Poll

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

    I have a perl script that runs continuously and launches other Perl
scripts. I'm using Proc::Simple to do this. I want to check and see if
the process (script) is already running, and if not, start it. I do
this by using the poll method. However, poll always returns 1, as if
the spawned process never terminates.

use Proc::Simple;
my $myproc4 = Proc::Simple->new();
$bool = "true";

     if($myproc4->poll() == 0)
    print "ALREADY RUNNING!\n";


In the above example, the first time I run this, the "if" is hit.
Thereafter, it is always the "else". Like I said, it's as if the
process never terminates. Also, if I watch the task manager, I see both
processes, and when the spawned process completes, it no longer appears
in the task manager.

I'm using ActivePerl on a WinXP Pro box.
Any help would be appreciated. Thanks.


Re: Proc::Simple - Poll

Quoted text here. Click to load it

Proc::Simple doesn't work properly on Win32. Most of the tests fail.
You would be better off using Win32::Process - which you'll already have
since you're using AS perl. Here's a tested example (that won't necessarily
do *exactly* what you want):

use warnings;
use strict;
use Win32::Process;

my $timeout = 1000; # milliseconds

my $ProcessObj;
my $exe = "D:\perl\bin\perl.exe"; # modify as needed
my $cmdline = "perl";
my $console_flag = CREATE_NEW_CONSOLE; # eg

     $priority | $console_flag,
     )|| die $^E;

# Wait() returns '1' if the process finished
# during the timeout period. Else returns 0.

while(!($ProcessObj->Wait($timeout))) {
     print "It's still running\n";

print " has finished\n";


'perldoc Win32::Process' is not as helpful as it might be (but check it out,
anyway). There's good documentation of his module in Chapter 8 of Dave
Roth's "Win32 Perl Programming: The Standard Extensions" (if you have access
to that book).


Re: Proc::Simple - Poll

Thanks, Rob.
This module works great for what I need. I appreciate the insight.


Site Timeline