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

Dear all,

I want to open a web page in Windows (Vista or XP) using the user's default browser. I found this way to do it: Re: Perl Windows Open a Web Browser in an earlier post:
use Win32::FileOp qw(ShellExecute); ShellExecute("http://www.perlmonks.org");
It works fine and quite fast actually. However, I haven't figured out a way to get the error code when things do not work as expected (e.g. when user does not have Internet connectivity).

I tried to get the error code with $^E as suggested in http://search.cpan.org/~jenda/Win32-FileOp-0.14.1/FileOp.pm but I get an undefined value in both connected and not-connected case. Is there a way around the problem or should I resort to other tools, like WWW::Mechanize, to check for connectivity?

Cheers,
Athanasia

Replies are listed 'Best First'.
Re: Get error code using ShellExecute to open browser
by BrowserUk (Patriarch) on Nov 10, 2008 at 12:19 UTC
      Thanks, this works like a charm!
Re: Get error code using ShellExecute to open browser
by Jenda (Abbot) on Nov 10, 2008 at 18:23 UTC

    You asked the module to start the default browser and pass it some parameter, that's what it did. It doesn't have any chance to find out what did that program do then. You may check whether the page is accessible using LWP::Simple, but this may fail if the script runs within the intranet of some company that doesn't allow direct access to web servers and requires the use of a HTTP proxy.

    If you did need the script to handle this it would have to look into the registry to find out which is the default browser, using some browser specific code find out the proxy and then use LWP::UserAgent and set the proxy parameters the same way they are in the browser. Probably too much work.