Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

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:05 UTC ( #603868=perlquestion: print w/ replies, xml ) Need Help??
tphyahoo has asked for the wisdom of the Perl Monks concerning the following question:

I have a bash script that opens a browser for a few seconds, and then closes it.

Could someone point me up the equivelant in perl?

I reckon this amounts to, what's the process for translating forking from bash to perl.

#!/bin/bash konqueror http://www.google.com & pid=$! # give the page some time to load sleep 5 kill $pid
UPDATE:

By the way, this isn't an academic question -- I'm using this simple script to verify various html downloads by checking the konqueror html cache for text strings I'm interested in, for pages that can't be easily downloaded with wget/web mechanize because of javascript and redirect nastiness.

Also, for those interested in shell-equivelance strategies, I posted essentially the same question to haskell-cafe.

Comment on open a browser from the command line, wait a few seconds, and shut it. (ie, translate forking from bash to perl)
Download Code
Re: open a browser from the command line, wait a few seconds, and shut it. (ie, translate forking from bash to perl)
by ikegami (Pope) on Mar 08, 2007 at 18:11 UTC
    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.

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

Re: open a browser from the command line, wait a few seconds, and shut it. (ie, translate forking from bash to perl)
by ikegami (Pope) on Mar 08, 2007 at 18:52 UTC
      I was aware of and decided to use these modules, but can't remember why anymore.

      I think it had something to do with them also not being ok with javascript. But I may have been wrong about that, and will give it another shot.

      Currently though, after perl -MCPAN -e 'install Mozilla::DOM' I'm getting

      *** can not find package for any of (mozilla-xpcom >= 1.7, firefox-xpc +om >= 1.0, mozilla-firefox-xpcom >= 1.0) *** check that one of them is properly installed and available in PKG_ +CONFIG_PATH

      apt-cache search isn't pulling these up on my ubuntu box. (and package management is completely &)#@ed on the SUSE 10.1 box I use at work.)

      UPDATE: regarding the above, I guess I need to start at http://developer.mozilla.org/en/docs/Build_Documentation

      (It's just not in .deb form yet).

      But I'm going home now, so perhaps to be continued.

        I just stumbled into the same situation yesterday ...
        Did you find a solution/work-around for this?


        Cheers,
        Tink

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://603868]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (11)
As of 2015-07-07 09:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (88 votes), past polls