List of usage examples for org.apache.commons.exec DefaultExecutor setExitValue
public void setExitValue(final int value)
From source file:com.cprassoc.solr.auth.util.CommandLineExecutor.java
public static int exec(String cmd) { int exitValue = -1; try {//from w w w . j a va2s. co m CommandLine cmdLine = CommandLine.parse(cmd); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValue(1); ExecuteWatchdog watchdog = new ExecuteWatchdog(60000); executor.setWatchdog(watchdog); exitValue = executor.execute(cmdLine); } catch (Exception e) { e.printStackTrace(); } return exitValue; }
From source file:common.UglyLaunchTempPatch.java
/** * code for lunching external jar file/* w w w.jav a 2 s . com*/ * * @param jarFile * the jar file that is being lunched * @param Server * is this a server lunch or not * @throws IOException * @throws ClassNotFoundException * @throws NoSuchMethodException * @throws InvocationTargetException * @throws IllegalAccessException * @throws InterruptedException */ public static void jar(File jarFile) throws IOException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, InterruptedException { Main.print("\"" + jarFile.getAbsolutePath() + "\""); // sets jar to deleate on exit of program jarFile.deleteOnExit(); //runs the client version of the forge installer. Map map = new HashMap(); map.put("file", jarFile); CommandLine cmdLine = new CommandLine("java"); cmdLine.addArgument("-jar"); cmdLine.addArgument("${file}"); cmdLine.setSubstitutionMap(map); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValue(0); ExecuteWatchdog watchdog = new ExecuteWatchdog(60000); executor.setWatchdog(watchdog); int exitValue = executor.execute(cmdLine); }
From source file:client.UglyLaunchTempPatch.java
/** * code for lunching external jar file//from www . j av a2s . com * * @param jarFile * the jar file that is being lunched * @param Server * is this a server lunch or not * @throws IOException * @throws ClassNotFoundException * @throws NoSuchMethodException * @throws InvocationTargetException * @throws IllegalAccessException * @throws InterruptedException */ public static void jar(File jarFile) throws IOException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, InterruptedException { main.print("\"" + jarFile.getAbsolutePath() + "\""); // sets jar to deleate on exit of program jarFile.deleteOnExit(); //runs the client version of the forge installer. Map map = new HashMap(); map.put("file", jarFile); CommandLine cmdLine = new CommandLine("java"); cmdLine.addArgument("-jar"); cmdLine.addArgument("${file}"); cmdLine.setSubstitutionMap(map); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValue(0); ExecuteWatchdog watchdog = new ExecuteWatchdog(60000); executor.setWatchdog(watchdog); int exitValue = executor.execute(cmdLine); }
From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.svmlib.SVMLibExperimentRunner.java
public static void runCommand(String command) throws IOException { CommandLine cmdLine = CommandLine.parse(command); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValue(0); // set one hour limit for training ExecuteWatchdog watchdog = new ExecuteWatchdog(1000 * 60 * 60); executor.setWatchdog(watchdog);/*from w w w .j av a 2 s . c o m*/ System.out.println("Running\n" + command); int exitValue = executor.execute(cmdLine); }
From source file:com.tribuneqa.utilities.FrameworkUtilities.java
public static void appiumStop() throws IOException { // Add different arguments In command line which requires to stop appium server. CommandLine command = new CommandLine("cmd"); command.addArgument("/c"); command.addArgument("taskkill"); command.addArgument("/F"); command.addArgument("/IM"); command.addArgument("node.exe"); // Execute command line arguments to stop appium server. DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler(); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValue(1); executor.execute(command, resultHandler); }
From source file:com.boundlessgeo.wps.grass.GrassProcesses.java
/** * Define a GISBASE/LOCATION_NAME for the provided dem. * * @param operation Name used for the location on disk * @param dem File used to establish CRS and Bounds for the location * @return/*from w ww. j a v a 2 s .co m*/ * @throws Exception */ static File location(CoordinateReferenceSystem crs) throws Exception { String code = CRS.toSRS(crs, true); File geodb = new File(System.getProperty("user.home"), "grassdata"); File location = Files.createTempDirectory(geodb.toPath(), code).toFile(); KVP kvp = new KVP("geodb", geodb, "location", location); // grass70 + ' -c epsg:' + myepsg + ' -e ' + location_path CommandLine cmd = new CommandLine(EXEC); cmd.addArgument("-c"); cmd.addArgument("epsg:" + code); cmd.addArgument("-e"); cmd.addArgument("${location}"); cmd.setSubstitutionMap(kvp); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValue(0); executor.setWatchdog(new ExecuteWatchdog(60000)); executor.setStreamHandler(new PumpStreamHandler(System.out)); int exitValue = executor.execute(cmd); return location; }
From source file:com.boundlessgeo.wps.grass.GrassProcesses.java
@DescribeProcess(title = "GRASS Version", description = "Retreive the version of GRASS used for computation") @DescribeResult(description = "Version") public static String version() { if (EXEC == null) { return "unavailable"; }/*from w ww . ja v a2s.co m*/ CommandLine cmd = new CommandLine(EXEC); cmd.addArgument("-v"); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValue(0); ExecuteWatchdog watchdog = new ExecuteWatchdog(60000); executor.setWatchdog(watchdog); try { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); executor.setStreamHandler(new PumpStreamHandler(outputStream)); LOGGER.info("exec: " + cmd.toString()); int exitValue = executor.execute(cmd); return outputStream.toString(); } catch (ExecuteException huh) { return "exit code: " + huh.getExitValue() + " (" + huh.getMessage() + ")"; } catch (IOException e) { return "unavailable: " + e.getClass().getSimpleName() + ":" + e.getMessage(); } }
From source file:com.boundlessgeo.wps.grass.GrassProcesses.java
/** * Define a GISBASE/LOCATION_NAME/PERMANENT for the provided dem. * * The dem is staged in GISBASE/dem.tif and then moved to * GISBASE/LOCATION_NAME/PERMANENT/dem.tif * * @param operation/*from w ww.j a v a 2 s . c o m*/ * Name used for the location on disk * @param dem * File used to establish CRS and Bounds for the location * @return Array of files consisting of {GISBASE, LOCATION, MAPSET, dem.tif} * @throws Exception */ static File location(File location, File raster) throws Exception { // grass70 + ' -c ' + myfile + ' -e ' + location_path CommandLine cmd = new CommandLine(EXEC); cmd.addArgument("-c"); cmd.addArgument("${raster}"); cmd.addArgument("-e"); cmd.addArgument("${location}"); cmd.setSubstitutionMap(new KVP("raster", raster, "location", location)); LOGGER.info(cmd.toString()); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValue(0); ExecuteWatchdog watchdog = new ExecuteWatchdog(60000); executor.setWatchdog(watchdog); executor.setStreamHandler(new PumpStreamHandler(System.out)); LOGGER.info(cmd.toString()); try { int exitValue = executor.execute(cmd); } catch (ExecuteException fail) { LOGGER.warning("grass70:" + fail.getLocalizedMessage()); throw fail; } File mapset = new File(location, "PERMANENT"); if (!mapset.exists()) { throw new IllegalStateException("Did not create mapset " + mapset); } return location; }
From source file:com.boundlessgeo.wps.grass.GrassProcesses.java
/** * Define a GISBASE/LOCATION_NAME/PERMANENT for the provided dem. * * The dem is staged in GISBASE/dem.tif and then moved to * GISBASE/LOCATION_NAME/PERMANENT/dem.tif * * @param operation//from w w w . java 2 s . c o m * Name used for the location on disk * @param dem * File used to establish CRS and Bounds for the location * @return Array of files consisting of {GISBASE, LOCATION, MAPSET, dem.tif} * @throws Exception */ static File[] location(String operation, GridCoverage2D dem) throws Exception { File geodb = new File(System.getProperty("user.home"), "grassdata"); //File location = Files.createTempDirectory(geodb.toPath(),operation).toFile(); File location = new File(geodb, operation); File mapset = new File(location, "PERMANENT"); File file = new File(geodb, "dem.tif"); final GeoTiffFormat format = new GeoTiffFormat(); GridCoverageWriter writer = format.getWriter(file); writer.write(dem, null); System.out.println("Staging file:" + file); // grass70 + ' -c ' + myfile + ' -e ' + location_path CommandLine cmd = new CommandLine(EXEC); cmd.addArgument("-c"); cmd.addArgument("${file}"); cmd.addArgument("-e"); cmd.addArgument("${location}"); cmd.setSubstitutionMap(new KVP("file", file, "location", location)); LOGGER.info(cmd.toString()); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValue(0); ExecuteWatchdog watchdog = new ExecuteWatchdog(60000); executor.setWatchdog(watchdog); executor.setStreamHandler(new PumpStreamHandler(System.out)); int exitValue = executor.execute(cmd); File origional = file; file = new File(mapset, file.getName()); Files.move(origional.toPath(), file.toPath()); return new File[] { geodb, location, mapset, file }; }
From source file:com.sds.acube.ndisc.mts.xserver.XNDiscServer.java
/** * XNDisc Server ? ? ?//from w w w .j a v a 2s .com * * @return ?? true, false */ private static boolean isXNDiscServerAlive() { boolean isAlive = false; String HOST = XNDiscConfig.getString(XNDiscConfig.HOST, XNDiscConfig.LOCAL_HOST); String PORT = XNDiscConfig.getString(XNDiscConfig.PORT); Scanner scanner = null; ByteArrayOutputStream baos = null; try { String os = System.getProperty("os.name").toLowerCase(); String ostype = (os.contains("windows")) ? "W" : "U"; CommandLine cmdline = new CommandLine("netstat"); cmdline.addArgument("-an"); if (ostype.equals("W")) { cmdline.addArgument("-p"); cmdline.addArgument("\"TCP\""); } else { // UNIX ? ? -an ? ? ? if (XNDiscUtils.isSolaris()) { cmdline.addArgument("-P"); cmdline.addArgument("tcp"); } else if (XNDiscUtils.isAix()) { cmdline.addArgument("-p"); cmdline.addArgument("TCP"); } } DefaultExecutor executor = new DefaultExecutor(); executor.setExitValue(0); baos = new ByteArrayOutputStream(); PumpStreamHandler sh = new PumpStreamHandler(baos); executor.setStreamHandler(sh); executor.execute(cmdline); String str = baos.toString(); if (str != null && str.length() > 0) { // ? XNDisc alive ?(XNDisc Server ? ?) scanner = new Scanner(str); while (scanner.hasNextLine()) { String readline = scanner.nextLine(); if (readline.contains(HOST) && readline.contains(PORT) && readline.contains(XNDISC_LISTEN_STATUS)) { isAlive = true; break; } } } } catch (Exception e) { e.printStackTrace(); isAlive = false; } finally { try { if (scanner != null) { scanner.close(); } if (baos != null) { baos.close(); } } catch (IOException e) { e.printStackTrace(); } } return isAlive; }