diff options
-rw-r--r-- | rteval/rteval.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/rteval/rteval.py b/rteval/rteval.py index beba49f..5843d78 100644 --- a/rteval/rteval.py +++ b/rteval/rteval.py @@ -68,10 +68,16 @@ from cputopology import CPUtopology pathSave={} def getcmdpath(which): + """ + getcmdpath is a method which allows finding an executable in the PATH + directories to call it from full path + """ if not pathSave.has_key(which): - cmd = '/usr/bin/which %s' % which - c = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) - pathSave[which] = c.stdout.read().strip() + for path in os.environ['PATH'].split(':'): + cmdfile = os.path.join(path, which) + if os.path.isfile(cmdfile) and os.access(cmdfile, os.X_OK): + pathSave[which] = cmdfile + break if not pathSave[which]: raise RuntimeError, "Command '%s' is unknown on this system" % which return pathSave[which] |