in reply to Re: Executing a program, displaying some status, and killing it
in thread Executing a program, displaying some status, and killing it
I realize you were probably doing a quick port, but there are a few things I would like to point out.
Fixing these, I would probably write it as follows:
my $child = fork; if ($child) { # I am in the parent...wait then kill for (1..10) { sleep 1; print "."; } kill 9, $child; } else { # Run the background program exec '/path/to/program > /dev/null 2>&1'; }
Update: an alternative method that avoids explicit forking, and perhaps looks a bit more Perlish:
my $pid = open my $cmdfh, "-|", '/path/to/program' or die "Cannot fork: $!\n"; for ( 1 .. 10 ) { print "."; sleep 1; } kill 9, $pid;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Executing a program, displaying some status, and killing it
by Spida (Acolyte) on Dec 12, 2004 at 16:58 UTC | |
by revdiablo (Prior) on Dec 13, 2004 at 17:53 UTC |