tags:

views:

73

answers:

3

I have an erlang program which runs a server on a local machine and I would like it to start a local web browser and point to itself on startup. How can I do this in a portable way across Windows XP. Vista, and Windows 7?

A: 

You can use the port api in erlang to start a normal command.

For open a browser you have multiple options:

  • Look to the IExplorer.exe or how its called and start it with the URL as a parameter
  • Use the rundll32.exe command to open a browser through the windows api. I guess this will use the configured browser, so this is recommended.
ZeissS
+1  A: 

Hi, try this:

URL = "http://www.google.com", os:cmd("\"C:\Program Files\Internet Explorer\iexplore.exe\"" ++ URL).

You might have to modify the path if IE isn't located in that folder.

Fabian Alenius
+2  A: 

I would suggest to use the following code on windows systems:

URL = "http://www.google.com/", os:cmd("start " ++ URL).

This has two advantages:
1) No need for the right path of the browser.
2) Works even if someone doesn't use IE.

Too bad I don't know of something similar on Linux or MacOS.

bsmr
Brilliant! That worked first time!
Zubair
bsmr: have a look at the Python source code for the browser module to understand how to achieve the same on Linux and other os for that matter.
jldupont
@jldupont: thank You for the hint!
bsmr
For macos replace "start" with "open" and you get the same effect.
Jeremy Wall