Here you can find the source of findInPath(String executable, String path, String pathSeparator)
Parameter | Description |
---|---|
executable | The full name of the program to find in the path . |
path | The value of the PATH environment variable. |
pathSeparator | The path separation character for the agent's OS. |
public static String findInPath(String executable, String path, String pathSeparator)
//package com.java2s; import java.io.File; public class Main { /**/*from w ww . j av a 2s . co m*/ * Works kind of like the "which" program; the method won't try to apply * PATHEXT to {@link executable} when searching the PATH. * @param executable The full name of the program to find in the {@link path}. * @param path The value of the PATH environment variable. * @param pathSeparator The path separation character for the agent's OS. * @return The absolute path to the {@link executable} if it was found in the path; * the original value of {@link executable} otherwise. */ public static String findInPath(String executable, String path, String pathSeparator) { final String[] parts = path.split(pathSeparator); for (String part : parts) { final File potentialExecutable = new File(part, executable); if (potentialExecutable.exists()) { executable = potentialExecutable.getAbsolutePath(); break; } } return executable; } }