Here you can find the source of findUnixExecutable(String unixCommandLineExecutables)
Parameter | Description |
---|---|
unixCommandLineExecutables | a parameter |
private static String findUnixExecutable(String unixCommandLineExecutables)
//package com.java2s; /***************************************************************************** * This file is part of the Prolog Development Tool (PDT) * //from w ww .ja v a 2 s. co m * Author: Lukas Degener (among others) * WWW: http://sewiki.iai.uni-bonn.de/research/pdt/start * Mail: pdt@lists.iai.uni-bonn.de * Copyright (C): 2004-2012, CS Dept. III, University of Bonn * * All rights reserved. This program is made available under the terms * of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html * ****************************************************************************/ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Collection; import java.util.Vector; public class Main { /** * @author Hasan Abdel Halim * * Finds the current SWI-Prolog executable for UNIX/BSD-BASED OS * @param unixCommandLineExecutables * @return the complete path of the executable otherwise it will return xpce */ private static String findUnixExecutable(String unixCommandLineExecutables) { String[] default_exec = unixCommandLineExecutables.split(","); // TODO shall we look for the env. variables as we do for Windows ? String[] appendPath = null; // Hack to resolve the issue of locating xpce in MacOS if (isMacOS()) { appendPath = new String[1]; appendPath[0] = "PATH=$PATH:" + System.getProperty("user.home") + "/bin:/opt/local/bin"; } try { for (String exec : default_exec) { Process process = Runtime.getRuntime().exec("which " + exec, appendPath); if (process == null) return null; BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream())); String path = br.readLine(); if (path == null || path.startsWith("no " + default_exec)) continue; else { return path; } } return default_exec[0]; } catch (IOException e) { return default_exec[0]; } } public static void split(String string, String search, Collection<String> results) { if (string == null) { return; } int i = -1; while ((i = string.indexOf(search, 0)) >= 0) { results.add(string.substring(0, i).trim()); string = string.substring(i + search.length()); } String rest = string.trim(); if (rest.length() > 0) { results.add(rest); } } public static String[] split(String string, String search) { Vector<String> v = new Vector<String>(); split(string, search, v); return v.toArray(new String[v.size()]); } /** * @return */ public static boolean isMacOS() { boolean mac = System.getProperty("os.name").indexOf("Mac") > -1; return mac; } }