Proc::Simple - Poll
am 18.01.2006 22:52:45 von jdenevan
Hello,
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";
while($bool)
{
if($myproc4->poll() == 0)
{
$myproc4->start("perl myScript.pl");
}
else
{
print "ALREADY RUNNING!\n";
}
sleep(10);
}
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.
Jim
Re: Proc::Simple - Poll
am 19.01.2006 03:36:05 von Sisyphus
wrote in message
news:1137621165.154841.50490@g47g2000cwa.googlegroups.com...
> Hello,
> I have a perl script that runs continuously and launches other Perl
> scripts. I'm using Proc::Simple to do this.
..
..
>
> I'm using ActivePerl on a WinXP Pro box.
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 myScript.pl";
my $priority = NORMAL_PRIORITY_CLASS;
my $console_flag = CREATE_NEW_CONSOLE; # eg
Win32::Process::Create(
$ProcessObj,
$exe,
$cmdline,
0,
$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 "myScript.pl has finished\n";
__END__
'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).
Cheers,
Rob