views:

120

answers:

3

I was trying to create a simple script to open a locally hosted web site for testing the css in 2 or more browsers. The default browser is IE7 and it opens the page fine but when I try to open a non default browser such as Firefox or Arora it just fails.

I am using the webbrowser module and have tried this several way as detailed in various sites across the web.

Is it possible and if so how?

A: 

This basically boils down to:

- run 'firefox "url"'
- run 'iexplore "url"'
- run 'other_browser "url"'

I don't know enough python to know how the system() call is implemented there but it should be quite simple.

dbemerlin
+1  A: 

Unfortunately, I don't have access to the code any more, but I once did a similar thing with the subprocess module. Basically I just fed subprocess the path to the browser I wanted to do.

Edit: You need Python 2.4 or later to use subprocess.

GreenMatt
Thanks for the tip, as I say above I hadn't thought about doing it this way.
The Great Gonzo
+2  A: 

Matt's right and it's a pretty useful module to know...

18.1. subprocess

IDLE 2.6.2      
>>> import subprocess
>>> chrome = 'C:\Users\Ted\AppData\Local\Google\Chrome\Application\chrome.exe'
>>> chrome_args = 'www.rit.edu'
>>> spChrome = subprocess.Popen(chrome+' '+chrome_args)
>>> print spChrome.pid
2124
tethys
This is correct, but you should quote the path and maybe even the URL.
Max Shawabkeh
I will give this a go. Thanks I hadn't thought about doing it this way!
The Great Gonzo
Yeap that did the trick. Thanks for the suggestion.
The Great Gonzo