2 # executable.py -- Utilities for dealing with external executables
8 """Is this an executable file?"""
9 return os
.path
.isfile(file) and os
.access(file, os
.X_OK
)
11 def find(file, dirs
=None):
12 """Search for an executable in a given list of directories.
13 If no directories are given, search according to the PATH
14 environment variable."""
16 dirs
= string
.split(os
.environ
["PATH"], os
.pathsep
)
18 if is_executable(os
.path
.join(path
, file)):
19 return os
.path
.join(path
, file)
20 elif is_executable(os
.path
.join(path
, "%s.exe" % file)):
21 return os
.path
.join(path
, "%s.exe" % file)
24 def output(cmd
, strip
=None):
25 """Run a command and collect all output"""
28 stdin
, stdout
= os
.popen4(cmd
)
29 assert(not stdin
.close())
30 except AttributeError:
34 stdout
= posix
.popen('%s 2>&1' % cmd
)
36 # Python 1.x on Windows (no cygwin)
37 # There's no easy way to collect output from stderr, so we'll
38 # just collect stdout.
39 stdout
= os
.popen(cmd
)
40 output
= stdout
.read()
41 assert(not stdout
.close())
43 return string
.strip(output
)
49 exit_code
= os
.system(cmd
)