944,093 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 3448
  • Python RSS
Jan 17th, 2007
0

PATH not known in Windows?

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dams is offline Offline
2 posts
since Jan 2007
Jan 17th, 2007
0

Re: PATH not known in Windows?

Write a small Python program like the one below and save it as PrintHello.py ...
Python Syntax (Toggle Plain Text)
  1. print "Hello"
  2.  
  3. raw_input("Press Enter to go on ... ")
Now run this program ...
Python Syntax (Toggle Plain Text)
  1. import subprocess
  2.  
  3. subprocess.call(["Python.exe", "PrintHello.py"])
It seems to find Python.exe without any problems.
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Jan 17th, 2007
0

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.
Python Syntax (Toggle Plain Text)
  1. import sys
  2. path_list= sys.path
  3. for eachPath in path_list :
  4. print eachPath
Reputation Points: 741
Solved Threads: 692
Nearly a Posting Maven
woooee is offline Offline
2,307 posts
since Dec 2006
Jan 18th, 2007
0

Re: PATH not known in Windows?

Click to Expand / Collapse  Quote originally posted by woooee ...
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.
Python Syntax (Toggle Plain Text)
  1. import sys
  2. path_list= sys.path
  3. for eachPath in path_list :
  4. print eachPath
PYTHONPATH is only used by Python internally to find modules etc.
This person wants to use Window's Environment Variable.
Reputation Points: 404
Solved Threads: 180
Nearly a Posting Virtuoso
bumsfeld is offline Offline
1,422 posts
since Jul 2005
Jan 18th, 2007
0

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dams is offline Offline
2 posts
since Jan 2007

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: Game Logic: Determining Aces
Next Thread in Python Forum Timeline: python code for opening the web browser





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


Follow us on Twitter


© 2011 DaniWeb® LLC