in reply to starting a process in the background, with a twist

I can't use any modules from CPAN, only those that come with one of the common Windows-oriented Perl distributions.

That's a bit like asking: "How can I get to the top of teh building when I've a broken leg and refuze to use the lift?"

I have to work in a very restricted environment where access to the internet is not allowed.

Can you carry in a flash drive? Or a CD/DVD? A floppy disk? At a pinch you could print the module(s) you need to paper at home, carry the paper in and type them in at work.

"how do I start a process in the background then kill it after a pre-defined amount of time?"

Ostensibly all you need is:

... my $pid = system 1, q[ c:\the\path\to\theProgram.exe /option1 /option2 + ]; sleep $timeout; kill 2, $pid; ...

But there are always complications. You'll want to capture the output; supply "user input'; click on pop-ups; and do it from a cgi script running in a VM hosted on a remote server in Timbuktu.


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.

The start of some sanity?

Replies are listed 'Best First'.
Re^2: starting a process in the background, with a twist
by Anonymous Monk on Mar 20, 2012 at 21:18 UTC

    Yes, I can download the tar.gzipped modules from CPAN and install them manually, but looking at the possibly relevant modules in the FAQ (Proc::Background, Win32::Process etc.) I saw that each of them has non-trivial dependencies.

    Anyway, your suggestion works (except that I needed kill 9 instead of kill 2). You are right that there are complications, for example you were right about the VM, there is one involved in the problem :), but for this specific case, it looks like that your solution will be adequate.

    Thanks!

    PS. I propose that this method (system 1, "program_name") be added to the relevant entry in perlfaq8, because it's simple and useful. A similar hack for Unix-like systems is already present there.

      PS. I propose that this method (system 1, "program_name") be added to the relevant entry in perlfaq8, because it's simple and useful. A similar hack for Unix-like systems is already present there.

      You could propose it to the Perl5 Porters via their mailing list by submitting a patch as described in perlhack#SUPER-QUICK-PATCH-GUIDE.


      Dave

      Maybe Win32::Spawn in Win32?