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

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.

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

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.

Thanks to you all for your quick answer!
The method with subprocess.call is exactly what I want and runs perfectly.
Bye,
Dams

This question has already been answered. Start a new discussion instead.