Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Pause and Resume Exe

by gautamparimoo (Beadle)
on Feb 27, 2013 at 11:24 UTC ( [id://1020850]=perlquestion: print w/replies, xml ) Need Help??

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

Hi

I have a perl executable which recurses a filesystem using File::Find now I want to implement a pause and resume functionality such that the exe pauses in current state(or preserves current position) is some key is pressed or some other exe tells it to pause and then resume when key is pressed again or other exe tells to resume:

I thought of two approaches: 1.Remember the current file being recursed in a output file . Now this output file will give the last file traversed if we stop the program and restart it . But I cannot recurse from that file (I can skip all file till that file but that would take a lot of time and would not really be like a pause)to resume the recursion.

2. Maintain a second exe which calls some function to pause the state of the main exe and then resume again through the second exe. But how can I do it?? Please help??

Now I was having a look at Win32::Process and tried the following code ::

use Win32::Process; use Win32; sub ErrorReport { print Win32::FormatMessage( Win32::GetLastError() ); } Win32::Process::Create($ProcessObj, "C:\\Perl\\bin\\perl.exe", "perl CC4.4.pl ", 1, NORMAL_PRIORITY_CLASS, ".")|| die ErrorReport(); $ProcessObj->Suspend(); $ProcessObj->Resume(); #$ProcessObj->Wait(INFINITE);

The above code is Script A and CC4.4.pl is Script B. Questions: $ProcessObj->Suspend() is given at the time of execution how do i arbitarily invoke it at any time? As the script A is running so I cannot tell it to suspend at runtime?

Replies are listed 'Best First'.
Re: Pause and Resume Exe
by BrowserUk (Patriarch) on Feb 27, 2013 at 11:46 UTC
    Maintain a second exe which calls some function to pause the state of the main exe

    See Win32::Process. Use it in the second script to start the first script. It has Suspend() and Resume() methods you can use on the process you start using it.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      But I have to specify in the beginning only when to suspend and resume the exe. Nothing can be given while script is already running

        But I have to specify in the beginning only when to suspend and resume the exe.

        No you don't.

        Script A uses Win32::Process::CreateProcess() to start perl.exe running script B. It gets a process handle back from that call.

        Script B is running asynchronously from Script A. And Script A can call $hproc->Suspend() and $hproc->Resume() whenever it chooses to.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-19 11:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found