943,678 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 2310
  • Python RSS
You are currently viewing page 1 of this multi-page discussion thread
Sep 29th, 2009
0

opening an exe from Program Files directory in windows

Expand Post »
Hi All,

I need to open a exe from python. For ex i used

Python Syntax (Toggle Plain Text)
  1. import os
  2. os.system("C:\Winamp\Winamp.exe")

but I need to open an exe from the "Program Files" directory. I get an error because of the space between "Program" and "Files".

Python Syntax (Toggle Plain Text)
  1. import os
  2. os.system("C:\Program Files\Winamp\Winamp.exe")
  3. >>'C:\Program' is not recognized as an internal or external command.

Anybody has the solution. It must be simple but I am not able to get it
Similar Threads
Reputation Points: 10
Solved Threads: 3
Newbie Poster
pysup is offline Offline
18 posts
since Sep 2009
Sep 29th, 2009
0

Re: opening an exe from Program Files directory in windows

Click to Expand / Collapse  Quote originally posted by pysup ...
Hi All,
Python Syntax (Toggle Plain Text)
  1. import os
  2. os.system("C:\Program Files\Winamp\Winamp.exe")
  3. >>'C:\Program' is not recognized as an internal or external command.

Anybody has the solution. It must be simple but I am not able to get it
Shouldn't you be doing it like
Python Syntax (Toggle Plain Text)
  1. import os
  2. os.system("C:\\Program\ Files\\Winamp\\Winamp.exe")
?
Reputation Points: 32
Solved Threads: 13
Junior Poster in Training
ryuslash is offline Offline
57 posts
since Jul 2009
Sep 29th, 2009
0

Re: opening an exe from Program Files directory in windows

I tried

Python Syntax (Toggle Plain Text)
  1. os.system("C:\\Program\ Files\\Winamp\\Winamp.exe")
  2. os.system("C:\\Program/ Files\\Winamp\\Winamp.exe")

I get the same error
Reputation Points: 10
Solved Threads: 3
Newbie Poster
pysup is offline Offline
18 posts
since Sep 2009
Sep 29th, 2009
0

Re: opening an exe from Program Files directory in windows

try:
python Syntax (Toggle Plain Text)
  1. temp_var=r("C:\Program files\Winamp\Winamp.exe")
  2. os.system(tempvar)
Im not sure if defining it as a raw variable would work but its worth a shot
Reputation Points: 35
Solved Threads: 32
Posting Pro in Training
leegeorg07 is offline Offline
428 posts
since Jul 2008
Sep 29th, 2009
0

Re: opening an exe from Program Files directory in windows

Maybe
python Syntax (Toggle Plain Text)
  1. os.system("\"C:\Program Files\Winamp\Winamp.exe\"")
might be silly, but who knows...
Reputation Points: 32
Solved Threads: 13
Junior Poster in Training
ryuslash is offline Offline
57 posts
since Jul 2009
Sep 29th, 2009
0

Re: opening an exe from Program Files directory in windows

Thanks leegeorg and ryuslash.. I tried both ways but i still get the same error.
Reputation Points: 10
Solved Threads: 3
Newbie Poster
pysup is offline Offline
18 posts
since Sep 2009
Sep 29th, 2009
0

Re: opening an exe from Program Files directory in windows

It's not possible that you don't actually have Winamp in Program Files? You said that you tested with C:\Winamp\Winamp.exe which worked?
Reputation Points: 32
Solved Threads: 13
Junior Poster in Training
ryuslash is offline Offline
57 posts
since Jul 2009
Sep 29th, 2009
0

Re: opening an exe from Program Files directory in windows

Click to Expand / Collapse  Quote originally posted by ryuslash ...
It's not possible that you don't actually have Winamp in Program Files? You said that you tested with C:\Winamp\Winamp.exe which worked?
Actually I just gave that as an example..

If it were not present then the error would be "The System cannot find the path specified"

but I get an error 'C:\Program' is not recognized as an internal or external command.

Maybe i should reinstall my program out of program files folder but i want to do it as a last resort
Last edited by pysup; Sep 29th, 2009 at 9:12 am. Reason: missed detail
Reputation Points: 10
Solved Threads: 3
Newbie Poster
pysup is offline Offline
18 posts
since Sep 2009
Sep 29th, 2009
0

Re: opening an exe from Program Files directory in windows

Thought so
Reputation Points: 32
Solved Threads: 13
Junior Poster in Training
ryuslash is offline Offline
57 posts
since Jul 2009
Sep 29th, 2009
1

Re: opening an exe from Program Files directory in windows

It took a bit of playing around, but think I've found a workaround for this....

I noticed in the docs for os.system() (Yes I RTFM!) it mentions that the subprocess.call() should be used instead.
So I had a go with subprocess.call() but I soon ran into very similar problems, it still didn't like the spaces in the path.

After a bit of playing around and using a bit of lateral thinking I decided to try using subprocess.call() to call 'cmd.exe' passing it the path to a program in 'Program Files' as a parameter.

Now, I don't have winamp installed on my pc, so I decided to try and fire up Audacity using the following code:
PYTHON Syntax (Toggle Plain Text)
  1. import subprocess
  2.  
  3. subprocess.call(r'C:\WINDOWS\system32\cmd.exe /C "C:\Program Files\Audacity\audacity.exe"')

And you know what?? It bloody works!

After that, I decided to try using os.system in exactly the same way (use it to fire up cmd.exe with the path to Audacity as a parameter):
PYTHON Syntax (Toggle Plain Text)
  1. import os
  2.  
  3. os.system(r'C:\WINDOWS\system32\cmd.exe /C "C:\Program Files\Audacity\audacity.exe"')
Guess what??
That worked too!

Woot woot!

You'll get a little cmd window that will pop-up alongside whatever program you fire up, but it will disappear when you close the program down again.

So, all you need to do is copy one of the bits of code posted above and then replace my path to Audacity with the path to your installation of Winamp!

Hope that solves your problem.
Cheers for now,
Jas.
Last edited by JasonHippy; Sep 29th, 2009 at 9:32 am. Reason: smelling pistakes!
Reputation Points: 590
Solved Threads: 123
Practically a Master Poster
JasonHippy is offline Offline
672 posts
since Jan 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Text Files
Next Thread in Python Forum Timeline: Cookies





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC