opening an exe from Program Files directory in windows

Thread Solved

Join Date: Sep 2009
Posts: 18
Reputation: pysup is an unknown quantity at this point 
Solved Threads: 1
pysup pysup is offline Offline
Newbie Poster

opening an exe from Program Files directory in windows

 
0
  #1
Sep 29th, 2009
Hi All,

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

  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".

  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
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 54
Reputation: ryuslash is an unknown quantity at this point 
Solved Threads: 10
ryuslash's Avatar
ryuslash ryuslash is offline Offline
Junior Poster in Training

Re: opening an exe from Program Files directory in windows

 
0
  #2
Sep 29th, 2009
Originally Posted by pysup View Post
Hi All,
  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
  1. import os
  2. os.system("C:\\Program\ Files\\Winamp\\Winamp.exe")
?
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 18
Reputation: pysup is an unknown quantity at this point 
Solved Threads: 1
pysup pysup is offline Offline
Newbie Poster

Re: opening an exe from Program Files directory in windows

 
0
  #3
Sep 29th, 2009
I tried

  1. os.system("C:\\Program\ Files\\Winamp\\Winamp.exe")
  2. os.system("C:\\Program/ Files\\Winamp\\Winamp.exe")

I get the same error
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 396
Reputation: leegeorg07 is an unknown quantity at this point 
Solved Threads: 31
leegeorg07's Avatar
leegeorg07 leegeorg07 is offline Offline
Posting Whiz

Re: opening an exe from Program Files directory in windows

 
0
  #4
Sep 29th, 2009
try:
  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
don't judge me because I'm a year 8!

'it is better to fight for something than to live for nothing'General George S Patton
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 54
Reputation: ryuslash is an unknown quantity at this point 
Solved Threads: 10
ryuslash's Avatar
ryuslash ryuslash is offline Offline
Junior Poster in Training

Re: opening an exe from Program Files directory in windows

 
0
  #5
Sep 29th, 2009
Maybe
  1. os.system("\"C:\Program Files\Winamp\Winamp.exe\"")
might be silly, but who knows...
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 18
Reputation: pysup is an unknown quantity at this point 
Solved Threads: 1
pysup pysup is offline Offline
Newbie Poster

Re: opening an exe from Program Files directory in windows

 
0
  #6
Sep 29th, 2009
Thanks leegeorg and ryuslash.. I tried both ways but i still get the same error.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 54
Reputation: ryuslash is an unknown quantity at this point 
Solved Threads: 10
ryuslash's Avatar
ryuslash ryuslash is offline Offline
Junior Poster in Training

Re: opening an exe from Program Files directory in windows

 
0
  #7
Sep 29th, 2009
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?
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 18
Reputation: pysup is an unknown quantity at this point 
Solved Threads: 1
pysup pysup is offline Offline
Newbie Poster

Re: opening an exe from Program Files directory in windows

 
0
  #8
Sep 29th, 2009
Originally Posted by ryuslash View Post
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 54
Reputation: ryuslash is an unknown quantity at this point 
Solved Threads: 10
ryuslash's Avatar
ryuslash ryuslash is offline Offline
Junior Poster in Training

Re: opening an exe from Program Files directory in windows

 
0
  #9
Sep 29th, 2009
Thought so
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 310
Reputation: JasonHippy is a jewel in the rough JasonHippy is a jewel in the rough JasonHippy is a jewel in the rough JasonHippy is a jewel in the rough 
Solved Threads: 54
JasonHippy's Avatar
JasonHippy JasonHippy is online now Online
Posting Whiz

Re: opening an exe from Program Files directory in windows

 
1
  #10
Sep 29th, 2009
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:
  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):
  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!
There are 10 types of people in this world.....
Those who understand binary .....
And those who don't!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC