List of usage examples for org.apache.commons.exec DefaultExecutor execute
public int execute(final CommandLine command) throws ExecuteException, IOException
From source file:com.kotcrab.vis.editor.Main.java
public static void main(String[] args) throws Exception { App.init();/*from ww w.ja v a 2 s . c om*/ if (OsUtils.isMac()) System.setProperty("java.awt.headless", "true"); LaunchConfiguration launchConfig = new LaunchConfiguration(); //TODO: needs some better parser for (int i = 0; i < args.length; i++) { String arg = args[i]; if (arg.equals("--scale-ui")) { launchConfig.scaleUIEnabled = true; continue; } if (arg.equals("--project")) { if (i + 1 >= args.length) { throw new IllegalStateException("Not enough parameters for --project <project path>"); } launchConfig.projectPath = args[i + 1]; i++; continue; } if (arg.equals("--scene")) { if (i + 1 >= args.length) { throw new IllegalStateException("Not enough parameters for --scene <scene path>"); } launchConfig.scenePath = args[i + 1]; i++; continue; } Log.warn("Unrecognized command line argument: " + arg); } launchConfig.verify(); editor = new Editor(launchConfig); Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration(); config.setWindowedMode(1280, 720); config.setWindowSizeLimits(1, 1, 9999, 9999); config.useVsync(true); config.setIdleFPS(2); config.setWindowListener(new Lwjgl3WindowAdapter() { @Override public boolean closeRequested() { editor.requestExit(); return false; } }); try { new Lwjgl3Application(editor, config); Log.dispose(); } catch (Exception e) { Log.exception(e); Log.fatal("Uncaught exception occurred, error report will be saved"); Log.flush(); if (App.eventBus != null) App.eventBus.post(new ExceptionEvent(e, true)); try { File crashReport = new CrashReporter(Log.getLogFile().file()).processReport(); if (new File(App.TOOL_CRASH_REPORTER_PATH).exists() == false) { Log.warn("Crash reporting tool not present, skipping crash report sending."); } else { CommandLine cmdLine = new CommandLine(PlatformUtils.getJavaBinPath()); cmdLine.addArgument("-jar"); cmdLine.addArgument(App.TOOL_CRASH_REPORTER_PATH); cmdLine.addArgument(ApplicationUtils.getRestartCommand().replace("\"", "%")); cmdLine.addArgument(crashReport.getAbsolutePath(), false); DefaultExecutor executor = new DefaultExecutor(); executor.setStreamHandler(new PumpStreamHandler(null, null, null)); executor.execute(cmdLine); } } catch (IOException ex) { ex.printStackTrace(); } Log.dispose(); System.exit(-3); } catch (ExceptionInInitializerError err) { if (OsUtils.isMac() && err.getCause() instanceof IllegalStateException) { if (ExceptionUtils.getStackTrace(err).contains("XstartOnFirstThread")) { System.out.println( "Application was not launched on first thread. Restarting with -XstartOnFirstThread, add VM argument -XstartOnFirstThread to avoid this."); ApplicationUtils.startNewInstance(); } } throw err; } }
From source file:net.orpiske.sdm.lib.Executable.java
/** * Executes a command//from ww w . ja v a 2s. co m * @param command the command to execute * @param arguments the arguments to pass to the command * @return the return code from the command * @throws ExecuteException * @throws IOException */ public static int exec(final String command, final String arguments) throws ExecuteException, IOException { CommandLine cmd = new CommandLine(command); cmd.addArguments(arguments); DefaultExecutor executor = new DefaultExecutor(); return executor.execute(cmd); }
From source file:generator.Utils.java
public static boolean exec(String command, File workingDir, String... args) { try {//from w w w. j a v a2 s . c o m CommandLine cmdLine = new CommandLine(command); cmdLine.addArguments(args, false); DefaultExecutor exe = new DefaultExecutor(); exe.setWorkingDirectory(workingDir); return exe.execute(cmdLine) == 0; } catch (Exception e) { return false; } }
From source file:com.github.brandtg.pantopod.tor.TorProxyManager.java
private static void stopProcess(File pidFile, int signalNumber) throws Exception { try (InputStream inputStream = new FileInputStream(pidFile)) { Integer pid = Integer.valueOf(IOUtils.toString(inputStream).trim()); String command = String.format("KILL -%d %d", signalNumber, pid); LOG.info("Executing {}", command); DefaultExecutor executor = new DefaultExecutor(); int retCode = executor.execute(CommandLine.parse(command)); LOG.info("{} exited with {}", command, retCode); } catch (Exception e) { LOG.error("Could not kill {}", pidFile, e); }//from w w w . j ava 2 s . c o m }
From source file:com.wipro.ats.bdre.tdimport.QueuedFileUploader.java
private static void importFile(FileCopyInfo fileCopying) throws IOException { try {/*from ww w.j a v a2 s . c om*/ String sCommandString; String subProcessId = fileCopying.getSubProcessId(); GetProcess getProcess = new GetProcess(); String params[] = { "-p", subProcessId }; ProcessInfo processInfo = getProcess.getParentInfoFromSubProcess(params); String monDirName = new GetProperties().getProperties(subProcessId, "td-load") .getProperty("monitored-dir-name"); String targetDirPath = "tdload/" + processInfo.getBusDomainId() + "/" + processInfo.getProcessTypeId() + "/" + processInfo.getProcessId(); String absoluteFilePath = "tdload/" + processInfo.getBusDomainId() + "/" + processInfo.getProcessTypeId() + "/" + processInfo.getProcessId() + "/" + fileCopying.getFileName(); String command = "sh " + MDConfig.getProperty("execute.script-path") + "/file-loader-remote.sh" + " " + absoluteFilePath + " " + fileCopying.getTdDB() + " " + fileCopying.getTdTable() + " " + fileCopying.getTdUserName() + " " + fileCopying.getTdPassword() + " " + fileCopying.getTdTpdid() + " " + fileCopying.getTdDelimiter() + " " + targetDirPath + " " + monDirName + " " + fileCopying.getFileName(); sCommandString = command; CommandLine oCmdLine = CommandLine.parse(sCommandString); LOGGER.debug("executing command :" + command); DefaultExecutor oDefaultExecutor = new DefaultExecutor(); //oDefaultExecutor.setExitValue(0); oDefaultExecutor.execute(oCmdLine); } catch (Exception e) { FileMonitor.addToQueue(fileCopying.getFileName(), fileCopying); LOGGER.error("Error in importing file into TD. Requeuing file " + fileCopying.getFileName(), e); throw new IOException(e); } }
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 av a 2 s . 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:com.tibco.tgdb.test.utils.ProcessCheck.java
/** * Check whether a process is running or not * @param pid pid of the process to monitor * @return true if process is running// w w w . ja va 2 s . c o m * @throws IOException IO exception */ public static boolean isProcessRunning(int pid) throws IOException { String line; if (OS.isFamilyWindows()) { //tasklist exit code is always 0. Parse output //findstr exit code 0 if found pid, 1 if it doesn't line = "cmd /c \"tasklist /FI \"PID eq " + pid + "\" | findstr " + pid + "\""; } else { //ps exit code 0 if process exists, 1 if it doesn't line = "ps -p " + pid; } CommandLine cmdLine = CommandLine.parse(line); DefaultExecutor executor = new DefaultExecutor(); executor.setStreamHandler(new PumpStreamHandler(null, null, null)); executor.setExitValues(new int[] { 0, 1 }); int exitValue = executor.execute(cmdLine); if (exitValue == 0) return true; else if (exitValue == 1) return false; else // should never get to here in theory since execute would throw exception return true; }
From source file:common.UglyLaunchTempPatch.java
/** * code for lunching external jar file/*from www . j a v a 2 s . co m*/ * * @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 w ww . ja v a 2s . c om*/ * * @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:com.sds.acube.ndisc.xmigration.util.XNDiscMigUtil.java
/** * console clear /* w w w . j a va 2 s . c o m*/ */ public static void clearConsoleOutput() { try { String os = System.getProperty("os.name").toLowerCase(); String ostype = (os.contains("windows")) ? "W" : "U"; if (ostype.equals("W")) { CommandLine cmdLine = CommandLine.parse("cls"); DefaultExecutor executor = new DefaultExecutor(); executor.execute(cmdLine); System.out.printf("%n%n%n%n%n%n%n%n%n%n%n%n%n%n%n%n%n%n%n%n%n%n%n%n%n%n%n%n%n%n%n", new Object[0]); } else { CommandLine cmdLine = CommandLine.parse("clear"); DefaultExecutor executor = new DefaultExecutor(); executor.execute(cmdLine); System.out.print(CLEAR_TERMINAL_ANSI_CMD); System.out.flush(); } } catch (IOException e) { } }