in reply to Using Win32::Process to prevent timeouts

The only time I've ever used Win32::Process is when I wanted to test whether I could connect to a remote resigtry. What would happen is that on some machines, it would hang and the script would basically stop.

I'm not sure what exactly you want to do, but Win32::Process is basically going to launch another application from your script. Here's what I did to launch a perl one-liner to test whether or not the connection attempt would hang.

sub RegConnect { my ($pObj, $ExitCode); my $comp = shift; my $pString = "perl -MWin32::TieRegistry -e " . '"' . '$Registry->Connect(' ."'" . $comp . "', 'LMachine');" . '"'; Win32::Process::Create($pObj, "c:\\perl\\bin\\perl.exe", $pString, 0, NORMAL_PRIORITY_CLASS, ".")|| die "Can't create Perl Process: $!\n"; $pObj->Wait(7000); $pObj->GetExitCode($ExitCode); if ($ExitCode) { $pObj->Kill(1); return 0; } return 1; }
Hope that's helpful,

Replies are listed 'Best First'.
(tye)Re: Using Win32::Process to prevent timeouts
by tye (Sage) on Feb 05, 2002 at 06:23 UTC

    Replacing the second argument with $^X will make this more portable (not to other operating systems, but to computers where Perl was installed to some place other than C:/Perl).

            - tye (but my friends call me "Tye")
      You know.. when I originally wrote this, I told myself to look up which variable held that data, knowing that I'd seen it before. Never got around to it.. good catch though.


Re: Re: Using Win32::Process to prevent timeouts
by fullyloaded (Initiate) on Feb 05, 2002 at 11:15 UTC
    well all i need is a way to prevent my script from timing out, because when i add a delay in my script it times out after about 4 minutes, i want to avoid this if possible. im not sure if the win32::process does this, i just saw it in another script and i assume thats what it was doing, do u have a piece of code u use ro prevent ur scripts from timing out? thanks :)
      Ahh.. I see. Well your question is a tricky one because we really don't know any details about what you're doing. "timing out" could mean a lot of things, and there's a lot of variables that could effect things. The best bet is to start a new Seekers of Perl Wisdom node, posting what your problem is, and the offending script. Details will be very important if you'd like help that's benificial.

      Hope this helps,