List of usage examples for org.apache.commons.exec ExecuteWatchdog ExecuteWatchdog
public ExecuteWatchdog(final long timeout)
From source file:com.cprassoc.solr.auth.util.CommandLineExecutor.java
public static int exec(String cmd) { int exitValue = -1; try {/* w w w . j a v 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: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 {// w ww.j a v a2 s. c o m 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);/*from ww w .j av a 2s. com*/ 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:common.UglyLaunchTempPatch.java
/** * code for lunching external jar file// w w w . j av 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:client.UglyLaunchTempPatch.java
/** * code for lunching external jar file//from ww w.j av a 2s . 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:io.selendroid.io.ShellCommand.java
public static String exec(CommandLine commandline, long timeoutInMillies) throws ShellCommandException { log.info("executing command: " + commandline); PritingLogOutputStream outputStream = new PritingLogOutputStream(); DefaultExecutor exec = new DefaultExecutor(); exec.setWatchdog(new ExecuteWatchdog(timeoutInMillies)); PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream); exec.setStreamHandler(streamHandler); try {//from ww w. j av a 2 s.c o m exec.execute(commandline); } catch (Exception e) { throw new ShellCommandException("An error occured while executing shell command: " + commandline, new ShellCommandException(outputStream.getOutput())); } return (outputStream.getOutput()); }
From source file:io.selendroid.standalone.io.ShellCommand.java
public static String exec(CommandLine commandline, long timeoutInMillies) throws ShellCommandException { log.info("Executing shell command: " + commandline); PrintingLogOutputStream outputStream = new PrintingLogOutputStream(); DefaultExecutor exec = new DefaultExecutor(); exec.setWatchdog(new ExecuteWatchdog(timeoutInMillies)); PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream); exec.setStreamHandler(streamHandler); try {//from w w w . j a v a2 s . c o m exec.execute(commandline); } catch (Exception e) { log.log(Level.SEVERE, "Error executing command: " + commandline, e); if (e.getMessage().contains("device offline")) { throw new DeviceOfflineException(e); } throw new ShellCommandException("Error executing shell command: " + commandline, new ShellCommandException(outputStream.getOutput())); } String result = outputStream.getOutput().trim(); log.info("Shell command output\n-->\n" + result + "\n<--"); return result; }
From source file:com.codeabovelab.dm.common.utils.ProcessUtils.java
public static ExecuteWatchdog createTimeoutWatchdog(TimeUnit timeunit, int timeout) { ExecuteWatchdog timeoutWatchdog = new ExecuteWatchdog(timeunit.toMillis(timeout)); return timeoutWatchdog; }
From source file:com.bptselenium.jenkins.BPTSeleniumJenkins.RunCommand.java
public static void runCommand(String command, TaskListener listener, Run<?, ?> build) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); CommandLine cmdLine = CommandLine.parse(command); ExecuteWatchdog watchdog = new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT); Executor executor = new DefaultExecutor(); PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream); executor.setStreamHandler(streamHandler); executor.setExitValue(10);/*from ww w . j a va2 s .c o m*/ executor.setWatchdog(watchdog); try { executor.execute(cmdLine); } catch (ExecuteException ee) { //getting a non-standard execution value, set build result to unstable Result result = Result.UNSTABLE; if (build.getResult() == null) { build.setResult(result); } else if (build.getResult().isBetterThan(result)) { build.setResult(result.combine(build.getResult())); } } catch (IOException e) { e.printStackTrace(); } finally { listener.getLogger().println(outputStream.toString()); } }
From source file:com.muk.ext.process.ProcessExecutor.java
public int runCommandLine(CommandLine cmdLine, long maxWaitTimeInMillis) throws IOException { ExecuteWatchdog processWatchDog = new ExecuteWatchdog(maxWaitTimeInMillis); Executor executor = new DefaultExecutor(); executor.setExitValue(0);//from w w w . ja va 2s . c o m executor.setWatchdog(processWatchDog); int result = 1; result = executor.execute(cmdLine); return result; }