diff -r 381665763704 -r 8d607cd52f26 Utilities/__init__.py --- a/Utilities/__init__.py Thu Nov 17 18:59:13 2016 +0100 +++ b/Utilities/__init__.py Fri Nov 18 18:34:34 2016 +0100 @@ -977,6 +977,50 @@ return paths +def getWindowsExecutablePath(file): + """ + Function to build the full path of an executable file from the environment + on Windows platforms. + + First an executable with the extension .exe is searched for, thereafter one + with the extension .bat and finally the given file name as is. The first + match is returned. + + @param file filename of the executable to check (string) + @return full executable name, if the executable file is accessible + via the searchpath defined by the PATH environment variable, or an + empty string otherwise. + """ + if os.path.isabs(file): + if os.access(file, os.X_OK): + return file + else: + return "" + + filenames = [file + ".exe", file + ".bat", file] + + for filename in filenames: + cur_path = os.path.join(os.curdir, filename) + if os.path.exists(cur_path): + if os.access(cur_path, os.X_OK): + return cur_path + + path = os.getenv('PATH') + + # environment variable not defined + if path is None: + return "" + + dirs = path.split(os.pathsep) + for dir in dirs: + for filename in filenames: + exe = os.path.join(dir, filename) + if os.access(exe, os.X_OK): + return exe + + return "" + + def isExecutable(exe): """ Function to check, if a file is executable.