os.system(cmd) isn't working

  • Thread starter =?ISO-8859-1?Q?Gregory_Pi=F1ero?=
  • Start date
?

=?ISO-8859-1?Q?Gregory_Pi=F1ero?=

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
 
P

Paul Watson

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.
1
 
F

F. Petitjean

Le Thu, 23 Jun 2005 01:19:11 -0500, Paul Watson a écrit :
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)
 
T

Tjarko de Jong

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")
 
D

Dennis Lee Bieber

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):

worked on my system -- but you probably /need/ to include the http
protocol prefix.


--
 
?

=?ISO-8859-1?Q?Gregory_Pi=F1ero?=

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(myhtmlroot,'').replace('\\','/')
url=htmlroot+'/'+filedir+'/'+filename
os.startfile(url)


-Greg
 
T

Terry Hancock

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? ;-)
 
P

Peter Hansen

Terry said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top