use IPC::Open2 qw( open2 ); my $pid = open2(my $to_child, my $from_child, 'konqueror', $url); sleep(5); kill(TERM => $pid);
Since we don't care about pipes, the above boils down to
my $pid = fork(); if (!defined($pid)) { die("Unable to fork: $!\n"); } if (!$pid) { exec('konqueror', $url); die("Unable to exec: $!\n"); } sleep(5); kill(TERM => $pid);
Don't forget to cleanup zombies using waitpid.
Update: Added second snippet.
Update: Oops! I was using kill($pid, TERM);. Thanks, Fletch.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: open a browser from the command line, wait a few seconds, and shut it. (ie, translate forking from bash to perl)
by tphyahoo (Vicar) on Mar 08, 2007 at 18:27 UTC | |
by Fletch (Bishop) on Mar 08, 2007 at 18:43 UTC |
In Section
Seekers of Perl Wisdom