Frandajo has asked for the wisdom of the Perl Monks concerning the following question:

Hello all,

I have a Tk program on ActiveState Perl for Win32 which can display its own manual in MSIE fine. I'd like to show it in Firefox instead if they have that browser.

Someone sent me this snippit. And it works fine for MSIE but makes Tk to hang while Firefox stays up after being called to show the doc.

Someone please tell me how to make it work as well for Firefox as it does for MSIE.

Thanks bunches,

# Launch new process the Win32 way. # Use alternate browser if installed. sub show_in_browser { no strict; if ( $browser =~ m/mozilla|firefox/ ) { # Display in Mozilla or its derivatives... $_ = shift || ''; my $command = m!^(?:ftp|http|file)://! ? sprintf URL, $_ : -r ($_) ? sprintf URL, 'file://' . abs_path($_) : s!^(www\..+)!http://$1! ? sprintf URL, $_ : s!^(ftp\..+)!ftp://$1! ? sprintf URL, $_ : s/^mailto:// ? sprintf MAIL, $_ : warn "usage: $0 (filename|URL|mailto:foo\@bar.com)\n" ; # Could add a LOG file output here. system "$browser", -remote => sprintf( $command, $_ ); } else { system( qq|start "$browser" "$browser"|, qq|"$_[0]"| ) && log_write( "Oops! Trouble opening $browser"); } }

Replies are listed 'Best First'.
Re: Open doc in Firefox from Tk with no Tk hanging
by eserte (Deacon) on Dec 08, 2007 at 00:04 UTC
    Does it work if you put 1 as first argument to system()? See perldoc perlport.

      Hey! Putting a "1, " in front works. Thanks!

Re: Open doc in Firefox from Tk with no Tk hanging
by renodino (Curate) on Dec 07, 2007 at 20:30 UTC
    Be advised forking from Perl on Win32 is only an emulation, implemented via threads.

    That said, you might consider Win32::WebBrowser *if* you actually want to open the user's default browser, whether its IE, FF, Opera, or even Safari. Or you can use its code to figure out how to force FF, its pretty simple, but you need to know the FF executable name/location.

    FWIW: Win32::WebBrowser's code is based on something I wrote for a Tk app, so hopefully it will solve your "hang" issue.


    Perl Contrarian & SQL fanboy
Re: Open doc in Firefox from Tk with no Tk hanging
by zentara (Cardinal) on Dec 07, 2007 at 18:22 UTC
    Try putting and & in your system to fork it off, and let Tk regain control.
    #untested system ("$browser", -remote => sprintf( $command, $_ ) &);

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum

      No, doesn't work. Can't on account of this is for Win32. Should have been more specific. Sorry. Thought it was eveident from the MSIE reference.