in reply to Terminating a parallel process opened with "system(..)"
I'm looking for a way to terminate a (parallel) process opened with by system('start','','some text file for example.txt'); preferably without relaying on non-core modules.
There is no way to do that using start.
The start command is a cmd.exe built-in, so system has to start a new copy of cmd.exe first, to run the start command. Then the start command determines the path & name of the executable associated with the filename you supplied and runs it. There is no way for Perl to know the process id of the process that the start command runs.
The only way to achieve your goal would be to emulate what the start command does -- look up the ftype assoc'd to the file type; then look up the path/executable name for that ftype; then invoke that executable directly.
When run as asyncStart-kill test.png, this starts my image editor with the test.png as its argument; waits 10 seconds and then kills it:
#! perl -slw use strict; my $filename = $ARGV[0]; my( $ext ) = $filename =~ m[(\.[^.]+)$]; my( $assoc ) = `assoc $ext` =~ m[=(.+)$]; my( $ftype ) = `ftype $assoc` =~ m[=(.+)$]; $ftype =~ s[^("[^"]+?"|\S+)\K.+$][]; #" print $ftype; my $pid = system 1, $ftype, $filename; print $pid; sleep 10; kill 9, $pid;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Terminating a parallel process opened with "system(..)"
by palkia (Monk) on May 30, 2012 at 18:01 UTC | |
by BrowserUk (Patriarch) on May 30, 2012 at 18:37 UTC | |
by palkia (Monk) on Jun 03, 2012 at 22:05 UTC | |
by BrowserUk (Patriarch) on Jun 03, 2012 at 22:31 UTC |