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.
In reply to Re: open a browser from the command line, wait a few seconds, and shut it. (ie, translate forking from bash to perl)
by ikegami
in thread open a browser from the command line, wait a few seconds, and shut it. (ie, translate forking from bash to perl)
by tphyahoo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |