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
In reply to Re: Run and Stop another program in perl
by roboticus
in thread Run and Stop another program in perl
by fast
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |