By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,486 Members | 1,127 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,486 IT Pros & Developers. It's quick & easy.

os.system(cmd) isn't working

P: n/a
Hi guys,

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.

I'm using Python 2.3 on Windows XP pro service pack 2.

I'd greatly appriciate any help.

Thanks,

Greg
Jul 19 '05 #1
Share this Question
Share on Google+
8 Replies

P: n/a
"Gregory Piñero" <gr********@gmail.com> wrote in message
news:ma**************************************@pyth on.org...
Hi guys,

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.

I'm using Python 2.3 on Windows XP pro service pack 2.

I'd greatly appriciate any help.

Thanks,

Greg

===============
These seemed to work on one machine for Python 2.1 and 2.4.
os.system('\"C:/Program Files/Mozilla Firefox/firefox.exe\"
http://www.blendedtechnologies.com/') 1 os.system('\"C:\\Program Files\\Mozilla Firefox\\firefox.exe\"
http://www.blendedtechnologies.com/') 1 os.system(r'"C:\Program Files\Mozilla Firefox\firefox.exe"
http://www.blendedtechnologies.com/')

1
Jul 19 '05 #2

P: n/a
Le Thu, 23 Jun 2005 01:19:11 -0500, Paul Watson a écrit :
"Gregory Piñero" <gr********@gmail.com> wrote in message
news:ma**************************************@pyth on.org...
Hi guys,

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.
I suggest to use the subprocess module. You don't have insert " around a
path with embedded spaces and you can give the exact executable
pathname, set the directory for the child process, etc

import os
import os.path
import subprocess
path_exe = r'C:\Program Files\Mozilla Firefox\firefox.exe'
assert os.path.exists(path_exe)
url = "http://www.blendedtechnologies.com"
child = subprocess.Popen( (path_exe, url), executable = path_exe)
rc = child.wait()
I'm using Python 2.3 on Windows XP pro service pack 2.
I think that subprocess is a new Python2.4 module, but you should be
able to find a 2.3 version (perhaps effbot.org)
I'd greatly appriciate any help.

Jul 19 '05 #3

P: n/a
On Thu, 23 Jun 2005 00:02:55 -0400, Gregory Piñero
<gr********@gmail.com> wrote:
Hi guys,

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.

I'm using Python 2.3 on Windows XP pro service pack 2.


What is wrong with:
os.startfile("www.blendedtechnologies.com")
Jul 19 '05 #4

P: n/a
On Thu, 23 Jun 2005 01:19:11 -0500, "Paul Watson"
<pw*****@redlinepy.com> declaimed the following in comp.lang.python:
"Gregory Piñero" <gr********@gmail.com> wrote in message
news:ma**************************************@pyth on.org...
Hi guys,

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.
Assuming Firefox is the default browser, and you are on windows
(as the C:\ indicates):
os.startfile(r"http://www.blendedtechnologies.com")


worked on my system -- but you probably /need/ to include the http
protocol prefix.
-- ================================================== ============ <
wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
================================================== ============ <
Home Page: <http://www.dm.net/~wulfraed/> <
Overflow Page: <http://wlfraed.home.netcom.com/> <

Jul 19 '05 #5

P: n/a
If firefox is not your default browser,
os.system(r'"cd c:\Program Files\Mozilla Firefox & firefox "' +
'"www.blendertechnologies.com"')

works for me.

Jul 19 '05 #6

P: n/a
Thanks to everyone for all the help! After careful consideration I
decided to go with os.startfile(url)

It works just great!

Here's my program in case anyone's interested. 5 points if you can
guess what it does ;-)

"""Take a filepath from stdin and translate to the corresponding url and
open up browser and show it."""
import sys
import os
myhtmlroot='C:\\Documents and Settings\\Gregory\\My
Documents\\blendedtechnologies\\trunk'
htmlroot='http://www.blendedtechnologies.com'
filepath=sys.argv[1]
filename=os.path.basename(filepath)
filedir=os.path.dirname(filepath).replace(myhtmlro ot,'').replace('\\','/')
url=htmlroot+'/'+filedir+'/'+filename
os.startfile(url)
-Greg
On 23 Jun 2005 10:04:32 -0700, dr******@gmail.com <dr******@gmail.com> wrote:
If firefox is not your default browser,
os.system(r'"cd c:\Program Files\Mozilla Firefox & firefox "' +
'"www.blendertechnologies.com "')

works for me.

--
http://mail.python.org/mailman/listinfo/python-list

Jul 19 '05 #7

P: n/a
On Thursday 23 June 2005 01:19 am, Paul Watson wrote:
"Gregory Piñero" <gr********@gmail.com> wrote in message
news:ma**************************************@pyth on.org...
os.system(r'"C:\Program Files\Mozilla Firefox\firefox.exe"' + '
"www.blendedtechnologies.com"')

The goal is to have firefox open to that website.


You don't have any spaces between the command and the argument,
I would assume they'd be necessary. I also notice you are quoting
the quotes here, so I presume you actually need them (maybe this is
because you have an embedded space in the filename?).

Need I mention that using filenames with spaces is a great evil? ;-)

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks http://www.anansispaceworks.com

Jul 19 '05 #8

P: n/a
Terry Hancock wrote:
On Thursday 23 June 2005 01:19 am, Paul Watson wrote:
"Gregory Piñero" <gr********@gmail.com> wrote in message
news:ma**************************************@py thon.org...
os.system(r'"C:\Program Files\Mozilla Firefox\firefox.exe"' + '
"www.blendedtechnologies.com"')

You don't have any spaces between the command and the argument,


I spent a while trying to prove that to myself as well, but eventually I
concluded that the fact that the ' and the " after the plus sign are on
separate lines must mean that there was whitespace between them, or the
line break would have occurred before the ' ... but it did seem like a
good theory while it lasted. ;-)

-Peter
Jul 19 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.