473,395 Members | 1,348 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

os.system(cmd) isn't working

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
8 4974
"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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: eichin | last post by:
One of my recent projects has involved taking an accretion of sh and perl scripts and "doing them right" - making them modular, improving the error reporting, making it easier to add even more...
1
by: Wayne Witzel III | last post by:
Using Python 2.3 Currently I process three files and build the output of those files in to lists using for statements. I think take those lists and provide them to an os.system() call. cmd...
1
by: Carl | last post by:
Dear friends, I have written a small Python program that executes "cmd" via os.system(cmd). My problem is that "cmd" runs on forever. More specifically, I want to run "cmd" for one hour on...
3
by: andrew | last post by:
Hi, I'm seeing the following error: ... system(cmd) UnicodeEncodeError: 'ascii' codec can't encode character u'\xe3' in position 57: ordinal not in range(128) and I think I vaguely...
1
by: Brice | last post by:
Hello I am new to python and I am really a bad programmer... As a linux user, I use quodlibet for listening to music. Quodlibet allows me to write plugins in python. I am trying to write...
14
by: gio | last post by:
I have a problem and the solution should works under windows and unix OS. Suppose I have a program ex.c in the directory X (so the current working directory of ex.c is X). Also suppose I have...
0
by: devoloperbattu | last post by:
in my project i have to nmap an ip give and in this code cmd = "nmap -O " + myip + "> /usr/local/apache2/htdocs/test/temp/tmp.txt" os.system(cmd) i scan for the os on the remote system. ...
1
by: earthdirt | last post by:
I'm a newbie and I'm in way over my head with a pressing real world problem I need to solve with python.....one that isn't waiting for me to learn all I need to learn about programming. I have 3...
3
by: =?GB2312?B?0rvK18qr?= | last post by:
Hi all, I'm looking for an RPC system working with twisted. 1. Binary. I want it run faster than any xml based RPC. 2. Bidirectional. Unlike HTTP, on which the client has to poll the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.