List of usage examples for org.apache.commons.exec DefaultExecutor DefaultExecutor
public DefaultExecutor()
From source file:com.yahoo.gondola.cli.GondolaAgent.java
public static void main(String[] args) throws ParseException, IOException { PropertyConfigurator.configure("conf/log4j.properties"); CommandLineParser parser = new DefaultParser(); Options options = new Options(); options.addOption("port", true, "Listening port"); options.addOption("config", true, "config file"); options.addOption("h", false, "help"); CommandLine commandLine = parser.parse(options, args); if (commandLine.hasOption("help")) { new HelpFormatter().printHelp("GondolaAgent", options); return;/*w w w . ja v a 2 s .c om*/ } if (commandLine.hasOption("port")) { port = Integer.parseInt(commandLine.getOptionValue("port")); } else { port = 1200; } if (commandLine.hasOption("config")) { configFile = commandLine.getOptionValue("config"); } config = new Config(new File(configFile)); logger.info("Initialize system, kill all gondola processes"); new DefaultExecutor().execute(org.apache.commons.exec.CommandLine.parse("bin/gondola-local-test.sh stop")); new GondolaAgent(port); }
From source file:com.kotcrab.vis.editor.Main.java
public static void main(String[] args) throws Exception { App.init();/* w w w . j a v a 2 s. c o m*/ 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:com.cprassoc.solr.auth.util.CommandLineExecutor.java
public static int exec(String cmd) { int exitValue = -1; try {//from www. j a v a 2s . c o 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:generator.Utils.java
public static boolean exec(String command, File workingDir, String... args) { try {/* w ww. j a v a 2 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:eu.forgestore.ws.util.Utils.java
public static int executeSystemCommand(String cmdStr) { CommandLine cmdLine = CommandLine.parse(cmdStr); final Executor executor = new DefaultExecutor(); // create the executor and consider the exitValue '0' as success executor.setExitValue(0);/*from w w w . j a va 2 s .c o m*/ ByteArrayOutputStream out = new ByteArrayOutputStream(); PumpStreamHandler streamHandler = new PumpStreamHandler(out); executor.setStreamHandler(streamHandler); int exitValue = -1; try { exitValue = executor.execute(cmdLine); } catch (ExecuteException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return exitValue; }
From source file:au.com.jwatmuff.genericp2p.windows.ExecUtil.java
public static String getStdoutForCommand(String cmd) { CommandLine cmdLine = CommandLine.parse(cmd); DefaultExecutor executor = new DefaultExecutor(); executor.setWatchdog(new ExecuteWatchdog(60000)); ByteArrayOutputStream stdout = new ByteArrayOutputStream(); executor.setStreamHandler(new PumpStreamHandler(stdout, null)); try {/*from w w w.j a va 2s.c om*/ executor.execute(cmdLine); } catch (ExecuteException e) { log.error("Exception executing '" + cmd + "'", e); } catch (IOException e) { log.error("IOException executing '" + cmd + "'", e); } return stdout.toString(); }
From source file:com.jivesoftware.os.jive.utils.shell.utils.Invoke.java
public static int invoke(File home, String[] command, final InputStream writeToProcess, final ConcurrentLinkedQueue<String> response) throws Exception { Executor executor = new DefaultExecutor(); executor.setExitValue(0);/*w w w . j av a 2 s . c o m*/ if (home != null) { executor.setWorkingDirectory(home); } //give all the processes 120s to return that they started successfully ExecuteWatchdog watchdog = new ExecuteWatchdog(120000); executor.setWatchdog(watchdog); LogOutputStream outputStream = new LogOutputStream(20000) { @Override protected void processLine(final String line, final int level) { response.add(line); } }; LogOutputStream errorStream = new LogOutputStream(40000) { @Override protected void processLine(final String line, final int level) { response.add(line); } }; PumpStreamHandler pumpStreamHandler = new PumpStreamHandler(outputStream, errorStream, writeToProcess); executor.setStreamHandler(pumpStreamHandler); executor.setProcessDestroyer(new ShutdownHookProcessDestroyer()); CommandLine commandLine = new CommandLine(command[0]); for (int i = 1; i < command.length; i++) { commandLine.addArgument(command[i]); } try { //executor.execute(commandLine, handler); return executor.execute(commandLine); //handler.waitFor(20000); } catch (Exception x) { x.printStackTrace(); return 1; } }
From source file:net.orpiske.sdm.lib.Executable.java
/** * Executes a command/* w w w.ja va 2s. c o 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:cat.ogasoft.protocolizer.processor.CompilerPhase.java
public static void processCompiler(RoundEnvironment roundEnv) throws CompilerException { try {/* w w w . ja v a 2 s. co m*/ String protocPath = "src" + File.separatorChar + "cat" + File.separatorChar + "ogasoft" + File.separatorChar + "protocolizer" + File.separatorChar + "protoc"; DefaultExecutor de = new DefaultExecutor(); for (Element element : roundEnv.getElementsAnnotatedWith(ProtoFileV2.Compiler.class)) { ProtoFileV2.Compiler compiler = element.getAnnotation(ProtoFileV2.Compiler.class); if (compiler.compile()) { String base = protocPath.replace('.', File.separatorChar); File dst = new File(base); if (!dst.exists() && !dst.mkdirs()) { throw new Exception("Cann not be created directory " + dst.getAbsolutePath()); } File rootDirectori = new File(base); //Compile all the files in compiler.protoFilePaths() FileFilter filter = new FileFilter() { @Override public boolean accept(File pathname) { return pathname.getName().toLowerCase().endsWith(".proto"); } }; for (File protoc : rootDirectori.listFiles(filter)) { String target = base + File.separatorChar + protoc.getName(); LOG.info("\tCompiling " + target + "..."); CommandLine cmd = CommandLine.parse(compiler.command() + " --proto_path=" + protocPath + " " + compiler.language().option + "=src " + target); int result = de.execute(cmd); if (result != 0) { throw new CompilerException("HO ho... somthing went wrong, code: " + result); } LOG.info("\t" + target + " compiled"); } } } } catch (Exception e) { //Any exception is a CompilerException. throw new CompilerException(e.getMessage()); } }
From source file:common.UglyLaunchTempPatch.java
/** * code for lunching external jar file//from ww w . java 2 s.c o 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); }