L
Lorin Hochstein
Hello all,
I'd like to retrieve the full path of an arbitrary program on a Unix
system (e.g. gcc). What's the nicest way to do this? Currently I'm
invoking the "which" program and parsing what it outputs to determine if
the output looks like a path.
Here's what I'm currently doing. Is there a more elegant way to do this?
def fullpath(prog):
"""Compute the full path of a program"""
s = os.popen('which ' + prog).readline()[:-1]
# Confirm that the return value looks like a path
r = re.compile('/(\w+/)*' + prog)
if r.match(s) is not None:
return s
else:
raise ValueError,s
Thanks,
Lorin
I'd like to retrieve the full path of an arbitrary program on a Unix
system (e.g. gcc). What's the nicest way to do this? Currently I'm
invoking the "which" program and parsing what it outputs to determine if
the output looks like a path.
Here's what I'm currently doing. Is there a more elegant way to do this?
def fullpath(prog):
"""Compute the full path of a program"""
s = os.popen('which ' + prog).readline()[:-1]
# Confirm that the return value looks like a path
r = re.compile('/(\w+/)*' + prog)
if r.match(s) is not None:
return s
else:
raise ValueError,s
Thanks,
Lorin