* Try to find the correct path to the given executable. * * If the path is relative(beginning with . or ..), or absolute, we already * have the correct path. Otherwise, try to find it with 'which' */
| 133 | * have the correct path. Otherwise, try to find it with 'which' |
| 134 | */ |
| 135 | std::string locate_executable(std::string executable) |
| 136 | { |
| 137 | if (!executable.length()) |
| 138 | { |
| 139 | return ""; |
| 140 | } |
| 141 | |
| 142 | /* If absolute/relative address, we can't do anything */ |
| 143 | if ((executable[0] == '/') || (executable[0] == '.')) |
| 144 | { |
| 145 | return executable; |
| 146 | } |
| 147 | |
| 148 | /* If just an executable, try to find it in PATH */ |
| 149 | auto path = read_output("which " + executable); |
| 150 | |
| 151 | return path; |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * Find the first position where ".." is, and then strip everything before that. |
no test coverage detected