Try to find full path of exec_name Parameters ---------- exec_name : str The executable name Returns ------- path : str The full path of executable if found, otherwise returns None
(exec_name)
| 259 | |
| 260 | |
| 261 | def which(exec_name): |
| 262 | """Try to find full path of exec_name |
| 263 | |
| 264 | Parameters |
| 265 | ---------- |
| 266 | exec_name : str |
| 267 | The executable name |
| 268 | |
| 269 | Returns |
| 270 | ------- |
| 271 | path : str |
| 272 | The full path of executable if found, otherwise returns None |
| 273 | """ |
| 274 | base_list = ["", "/bin"] + os.environ.get("PATH", "").split(os.pathsep) |
| 275 | for path in base_list: |
| 276 | full_path = os.path.join(path, exec_name) |
| 277 | if os.path.isfile(full_path) and os.access(full_path, os.X_OK): |
| 278 | return full_path |
| 279 | return None |