in reply to Start a service, wait 10 seconds, and stop the service.

Blasphemy time ... why not just write a shell command instead of a Perl script for this? For example, here is what i use to restart our mod_perl enable web server for Krang:

/usr/local/krang/bin/krang_ctl stop sleep 2 /usr/local/krang/bin/krang_ctl start
Use the right tool for the right job. :)

UPDATE: oh uh ... i see now that i got your order backwards ... start, wait, then stop. I'd still be tempted to solve this with a shell script rather than Perl, because you are dealing mostly with shell commands. One naive solution would be to grep for the process, but i'm sure there is a better way to capture the PID and stop it. Perhaps if you wrote some wrapper script like the apachectl script that keeps track of its PID. It writes the PID to a file and reads that file when you need to stop it. You could write the wrapper in Perl and have it accept two args: start and stop -- then use a shell script to call the Perl script.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re^2: Start a service, wait 10 seconds, and stop the service.
by tphyahoo (Vicar) on Jun 17, 2005 at 16:07 UTC
    Thanks for the quick response but.. well, is there a way to do that for tor? That's what I'm trying to do. My real script of course does stuff more complex than waiting ten seconds. :)

    UPDATE: Tor can be installed as a windows service, so I guess this question boils down to, how do I start a windows service, wait a bit, and stop it. Any ideas?

      ahhh, well next time you should mention that your script does more than sleep 10 sec...otherwise you will get an answer to what you've asked (simple and straight to the point....)