1 # Copyright (c) Twisted Matrix Laboratories.
2 # See LICENSE for details.
5 Utilities for dealing with processes.
10 def which(name, flags=os.X_OK):
11 """Search PATH for executable files with the given name.
13 On newer versions of MS-Windows, the PATHEXT environment variable will be
14 set to the list of file extensions for files considered executable. This
15 will normally include things like ".EXE". This fuction will also find files
16 with the given name ending with any of these extensions.
18 On MS-Windows the only flag that has any meaning is os.F_OK. Any other
19 flags will be ignored.
22 @param name: The name for which to search.
25 @param flags: Arguments to L{os.access}.
28 @param: A list of the full paths to files found, in the
29 order in which they were found.
32 exts = filter(None, os.environ.get('PATHEXT', '').split(os.pathsep))
33 path = os.environ.get('PATH', None)
36 for p in os.environ.get('PATH', '').split(os.pathsep):
37 p = os.path.join(p, name)
38 if os.access(p, flags):
42 if os.access(pext, flags):