in reply to Win32: timing out a perl subroutine
If the code in the $ProcessObj calls exit() on its own, the exit value will be retreivable via:use Win32::Process; Win32::Process::Create($ProcessObj, "c:\\Perl\\bin\\perl.exe", "perl -e \"print q(yr code here\n)\"", 1, NORMAL_PRIORITY_CLASS, ".") $a = $ProcessObj->Wait(1000); # units = ms $ProcessObj->Kill($some_exit_code); print "[$a] ==> I *think* this will be zero if the " . " process terminated on its own before Wait() finished\n";
Not the most elegant solution (what with having to respecify the path for perl.exe, and I assume it's more memory intensive) but that's Win32 for you.$ProcessObj->GetExitCode($exitvalue); print "The code returned: $exitvalue\n";
N.B.: That '1' means that the new process inherits the same filehandles as the code that produces it. If you don't want that, change it to '0'.
There's a lot of additional flags besides NORMAL_PRIORITY_CLASS. In particular, you can use
(Note that's a bitwise or in the last example.) These flags are really poorly documented - I recommend finding one of Dave Roth's Win32 books).DETACHED_PROCESS CREATE_NEW_CONSOLE DETACHED_PROCESS | IDLE_PRIORITY_CLASS
-- Frag.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Win32: timing out a perl subroutine
by osfameron (Hermit) on Jun 20, 2001 at 14:42 UTC | |
by osfameron (Hermit) on Jun 21, 2001 at 13:23 UTC |