DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Python (http://www.daniweb.com/forums/forum114.html)
-   -   PATH not known in Windows? (http://www.daniweb.com/forums/thread67592.html)

dams Jan 17th, 2007 10:17 am
PATH not known in Windows?
 
Hello,

I am new to Python and find it really nice.
But I can not launch an executable file using only its name. I have to give its whole path. I expected that the PATH environment variable is known by Python and that it could retrieve the full path itself...
I use Windows XP, Python 2.5 and os.spawnl to launch the executable file.
Thanks in advance for your help!

dams

vegaseat Jan 17th, 2007 4:39 pm
Re: PATH not known in Windows?
 
Write a small Python program like the one below and save it as PrintHello.py ...
print "Hello"
 
raw_input("Press Enter to go on ... ")
Now run this program ...
import subprocess
 
subprocess.call(["Python.exe", "PrintHello.py"])
It seems to find Python.exe without any problems.

woooee Jan 17th, 2007 9:07 pm
Re: PATH not known in Windows?
 
This will print your PYTHONPATH. If the path you want is not listed, and it shouldn't be because your program isn't found, then you have to use sys.path.append to add it.
import sys
path_list= sys.path
for eachPath in path_list :
  print eachPath

bumsfeld Jan 18th, 2007 11:52 am
Re: PATH not known in Windows?
 
Quote:

Originally Posted by woooee (Post 302803)
This will print your PYTHONPATH. If the path you want is not listed, and it shouldn't be because your program isn't found, then you have to use sys.path.append to add it.
import sys
path_list= sys.path
for eachPath in path_list :
  print eachPath

PYTHONPATH is only used by Python internally to find modules etc.
This person wants to use Window's Environment Variable.

dams Jan 18th, 2007 3:48 pm
Re: PATH not known in Windows?
 
Thanks to you all for your quick answer!
The method with subprocess.call is exactly what I want and runs perfectly.
Bye,
Dams


All times are GMT -4. The time now is 4:18 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC