Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Using Win32::Process to prevent timeouts

by fullyloaded (Initiate)
on Feb 05, 2002 at 02:17 UTC ( #143338=perlquestion: print w/replies, xml ) Need Help??

fullyloaded has asked for the wisdom of the Perl Monks concerning the following question:

hi, i am wanting a way to prevent my perl script from timing out, at the moment the only way i know how, or think i know how is to use the Win32::Process module, i have looked at it on cpan, but i am still not sure how to use it, the code is something like...
Use Win32::Process; Win32::Process::Create($ProcessObj, "D:\\winnt35\\system32\\notepad.exe", "notepad temp.txt", 0, NORMAL_PRIORITY_CLASS, ".")|| die ErrorReport(); $ProcessObj->Wait(INFINITE);
its the middle part where i create my object that im not exactly sure what i am suppose to put in there or how the whole thing works overall, i cant figure it out? thanks to anyone that can help me out :)

Replies are listed 'Best First'.
Re: Using Win32::Process to prevent timeouts
by rchiav (Deacon) on Feb 05, 2002 at 03:14 UTC
    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,
    Rich

      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.

        Rich

      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,
        Rich

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://143338]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2021-09-28 08:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?