Have you looked at Win32::Process? If I'm interpreting you correctly, this seems to give you what you want:
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";
If the code in the $ProcessObj calls exit() on its own, the exit value will be retreivable via:
$ProcessObj->GetExitCode($exitvalue); print "The code returned: $exitvalue\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.

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

DETACHED_PROCESS CREATE_NEW_CONSOLE DETACHED_PROCESS | IDLE_PRIORITY_CLASS
(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).

-- Frag.


In reply to Re: Win32: timing out a perl subroutine by frag
in thread Win32: timing out a perl subroutine by osfameron

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.