http://qs321.pair.com?node_id=603869


in reply to open a browser from the command line, wait a few seconds, and shut it. (ie, translate forking from bash to perl)

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.

  • Comment on Re: open a browser from the command line, wait a few seconds, and shut it. (ie, translate forking from bash to perl)
  • Select or Download Code

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
    Neither of these snippets behaves like the bash snippet, though.

    Konqueror is opened, but then not shut.

      Flip the order of the arguments to kill, kill( TERM => $pid ) (/msg'd ikegami about this as well).