in reply to Run and Stop another program in perl
fast:
If you use fork (on an operating system that supports it well), you can set up the I/O streams and fork off the task. Then you'll have the PID (process identifier) for the forked job, and you can kill it when you decide to. Something like:
my $child_PID = fork; if ($child_PID == 0) { # We're in the child process, so redirect I/O handles and run progr +am... close STDOUT; open STDOUT, '>', 'foobar.log' or die $!; exec 'foobar.exe', 'argument_1', 'second argument', 'etc...'; die "Couldn't find foobar.exe!"; # should never get here... } else { # We're in the parent, so wait a few seconds, and kill the child. sleep 10; kill 9, $child_PID; }
Untested code. Testing (and any repairs required) left as an exercise for the reader...
...roboticus
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Run and Stop another program in perl
by BrowserUk (Patriarch) on Aug 21, 2010 at 06:18 UTC | |
by roboticus (Chancellor) on Aug 21, 2010 at 11:28 UTC | |
|
Re^2: Run and Stop another program in perl
by JavaFan (Canon) on Aug 21, 2010 at 08:42 UTC | |
by BrowserUk (Patriarch) on Aug 21, 2010 at 09:03 UTC |