Finding the full path of an executable

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Sat Jan 17 11:00:27 CET 2009


En Fri, 16 Jan 2009 23:08:27 -0200, escribiste en el grupo
gmane.comp.python.general
> Unknown wrote:
>> On 2009-01-16, Michael Hoffman <9qobl2n02 at sneakemail.com> wrote:
>>> Is there a portable way to find the full path of a filename that would  
>>> be called by os.execvp()?

> The correct answer would be "/bin/echo" but abspath("echo") is just  
> going to give me <cwd>/echo. I need something that will search through  
> the PATH like execvp() would. I can do it myself, but I'm surprised that  
> such a feature is not already readily available somewhere.

py> import distutils.spawn
py> help(distutils.spawn.find_executable)
Help on function find_executable in module distutils.spawn:

find_executable(executable, path=None)
      Try to find 'executable' in the directories listed in 'path' (a
      string listing directories separated by 'os.pathsep'; defaults to
      os.environ['PATH']).  Returns the complete filename or None if not
      found.

py> distutils.spawn.find_executable("sc")
'C:\\WINDOWS\\system32\\sc.exe'

-- 
Gabriel Genellina




More information about the Python-list mailing list