protected String resolvCmdPath(String path) { List<String> pathelements = new ArrayList<String>(); pathelements.addAll(Arrays.asList(path.split(";"))); String envPath = System.getenv("PATH"); if(envPath != null && !envPath.isEmpty()) { pathelements.addAll(Arrays.asList(envPath.split(System.getProperty("path.separator")))); } String cmdname = getPd().getSpecific("command"); log(Level.DEBUG, "will look for %s in %s", cmdname, pathelements); for(String pathdir: pathelements) { File tryfile = new File(pathdir, cmdname); log(Level.TRACE, "trying if %s can execute", tryfile); if(tryfile.canExecute()) { log(Level.DEBUG, "will use %s as a command", tryfile.getAbsolutePath()); cmd = tryfile.getAbsolutePath(); break; } } if(cmd == null) { log(Level.ERROR, "command %s not found", cmdname); } return cmd; }
Process urlperfps = null; try { log(Level.DEBUG, "executing: %s", cmd); urlperfps = Runtime.getRuntime().exec(getCmd()); try (InputStream stdout = urlperfps.getInputStream()) { log(Level.ERROR, e, "external command failed : %s", e); log(Level.ERROR, " command %s failed with %s", cmd, errostring); perfstring = ""; log(Level.ERROR, e, "Exception on close: %s", e); } catch (InterruptedException e) { Thread.currentThread().interrupt(); log(Level.DEBUG, "returned line: %s", perfstring); return perfstring;