os.system(cmd) isn't working
Tim Golden
tim.golden at viacom-outdoor.co.uk
Thu Jun 23 02:19:19 EDT 2005
[Gregory Piñero]
|
| I'm trying to run this statement:
|
| os.system(r'"C:\Program Files\Mozilla Firefox\firefox.exe"' + '
| "www.blendedtechnologies.com"')
|
| The goal is to have firefox open to that website.
|
| When I type r'"C:\Program Files\Mozilla Firefox\firefox.exe"' + '
| "www.blendedtechnologies.com"' in the python interpreter I get:
|
| '"C:\\Program Files\\Mozilla Firefox\\firefox.exe"
| "www.blendedtechnologies.com"'
|
| And when I copy this into my command prompt (less outermost ' )
| firefox opens up to that page like I would expect. However in python
| nothing happens and I get exit status 1.
This is only half an answer, but I personally find faffing
about with the double-quote / double-backslash stuff between
Python and Windows a pain in the neck, so where I can I avoid it.
In this case, you have a few options:
1) Use the webbrowser module.
import webbrowser
webbrowser.open ("www.blendedtechnologies.com")
2) Use os.startfile (or its beefed-up cousin win32api.ShellExecute):
import os
os.startfile ("http://www.blendedtechnologies.com")
3) Find out from Windows where the default browser is:
(There are alternative ways of doing this, for
example querying the registry for AppPaths).
import os
import tempfile
import win32api
f = tempfile.TemporaryFile (suffix=".html")
hInstance, exe_filename = win32api.FindExecutable (f.name)
os.system ("%s %s" % (exe_filename, "www.blendedtechnologies.com"))
Hope all that leads you somewhere. Obviously, it doesn't
answer the underlying question about double-slashes and
quotes and so on, but it seems to meet your current need.
TJG
________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________
More information about the Python-list
mailing list