Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Proc::Simple - Poll
January 18, 2006, 6:52 pm
rate this thread
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.
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
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):
my $timeout = 1000; # milliseconds
my $exe = "D:\perl\bin\perl.exe"; # modify as needed
my $cmdline = "perl myScript.pl";
my $priority = NORMAL_PRIORITY_CLASS;
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.
print "It's still running\n";
print "myScript.pl 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).