Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

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

by ikegami (Patriarch)
on Mar 08, 2007 at 18:11 UTC ( #603869=note: print w/replies, xml ) Need Help??


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).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://603869]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2022-05-25 13:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (90 votes). Check out past polls.

    Notices?