|
Posted by jdenevan on January 18, 2006, 1:52 pm
Please log in for more thread options
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
|
|
Posted by Sisyphus on January 18, 2006, 9:36 pm
Please log in for more thread options
> 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
|
|
Posted by jdenevan on January 19, 2006, 3:12 pm
Please log in for more thread options
Thanks, Rob.
This module works great for what I need. I appreciate the insight.
Jim
|
| Similar Threads | Posted | | Has anyone had success with Proc::Simple on Win32? | September 10, 2007, 9:36 am |
| Proc::ProcessTable | August 4, 2004, 9:00 am |
| Proc::ProcessTable size differences | November 7, 2004, 12:17 am |
| Has the interface to Proc::PID_File changed? | January 5, 2005, 4:49 am |
| ANNOUNCE: PTools-Proc-NWay | May 11, 2007, 12:43 pm |
| Issues with Proc::ProcessTable module on Solaris 9 | April 20, 2007, 8:02 am |
| XML::Simple Help? | April 23, 2005, 5:09 pm |
| Help in XML::Simple | July 1, 2005, 9:12 pm |
| Getopt::Simple V 1.47 | July 29, 2004, 7:18 am |
| Simple question | September 15, 2005, 4:17 am |
|