List of usage examples for org.apache.commons.exec DefaultExecutor execute
public int execute(final CommandLine command) throws ExecuteException, IOException
From source file:com.dangdang.ddframe.job.plugin.job.type.integrated.ScriptElasticJob.java
@Override protected void executeJob(final JobExecutionMultipleShardingContext shardingContext) { String scriptCommandLine = getJobFacade().getScriptCommandLine(); Preconditions.checkArgument(!Strings.isNullOrEmpty(scriptCommandLine), "Cannot find script command line."); CommandLine cmdLine = CommandLine.parse(scriptCommandLine); cmdLine.addArgument(shardingContext.toScriptArguments(), false); DefaultExecutor executor = new DefaultExecutor(); try {//from w w w . j a va2 s . com executor.execute(cmdLine); } catch (final IOException ex) { throw new JobException(ex); } }
From source file:com.k42b3.aletheia.filter.response.Application.java
public void exec(Response response) throws Exception { if (response instanceof com.k42b3.aletheia.protocol.http.Response) { com.k42b3.aletheia.protocol.http.Response httpResponse = (com.k42b3.aletheia.protocol.http.Response) response; String contentType = httpResponse.getHeader("Content-Type"); if (Aletheia.getInstance().getConfig().getApplications().containsKey(contentType)) { String path = Aletheia.getInstance().getConfig().getApplications().get(contentType); String url = Aletheia.getInstance().getActiveUrl().getText(); String cmd = path.replace("${url}", url); try { logger.info("Call " + cmd); CommandLine commandLine = CommandLine.parse(cmd); DefaultExecutor executor = new DefaultExecutor(); executor.execute(commandLine); } catch (Exception e) { Aletheia.handleException(e); }/*from ww w . ja v a 2s . c o m*/ } } }
From source file:com.abiquo.nodecollector.service.impl.StonithServiceImpl.java
protected boolean executeCommand(final CommandLine command) { try {//from w w w. j av a 2 s.c o m LOGGER.debug(String.format("Executing '%s'", command.toString())); DefaultExecutor executor = new DefaultExecutor(); return executor.execute(command) == 0; } catch (Exception e) { LOGGER.error(String.format("While executing '%s'", command.toString()), e); return false; } }
From source file:com.kotcrab.vis.editor.CrashReporter.java
private void restart() { new Thread(() -> { try {/* w w w . ja v a 2s . c o m*/ CommandLine cmdLine = CommandLine.parse(restartCommand); DefaultExecutor executor = new DefaultExecutor(); executor.execute(cmdLine); } catch (IOException e) { e.printStackTrace(); } }).start(); }
From source file:com.demandware.vulnapp.challenge.impl.CommandInjectionChallenge.java
private String getCommandOutput(String command) { String output = null;// w ww . ja va2s . com try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { CommandLine cmd = new CommandLine("/bin/bash"); String[] args = new String[] { "-c", command }; cmd.addArguments(args, false); PumpStreamHandler psh = new PumpStreamHandler(outputStream); DefaultExecutor exec = new DefaultExecutor(); exec.setStreamHandler(psh); exec.execute(cmd); output = outputStream.toString(); } catch (ExecuteException e) { e.printStackTrace(); output = "Could not execute command"; } catch (IOException e) { e.printStackTrace(); } return output; }
From source file:com.creactiviti.piper.core.taskhandler.script.Bash.java
@Override public String handle(Task aTask) throws Exception { File scriptFile = File.createTempFile("_script", ".sh"); File logFile = File.createTempFile("log", null); FileUtils.writeStringToFile(scriptFile, aTask.getRequiredString("script")); try (PrintStream stream = new PrintStream(logFile);) { Process chmod = Runtime.getRuntime().exec(String.format("chmod u+x %s", scriptFile.getAbsolutePath())); int chmodRetCode = chmod.waitFor(); if (chmodRetCode != 0) { throw new ExecuteException("Failed to chmod", chmodRetCode); }//from w w w . ja va 2 s .c om CommandLine cmd = new CommandLine(scriptFile.getAbsolutePath()); logger.debug("{}", cmd); DefaultExecutor exec = new DefaultExecutor(); exec.setStreamHandler(new PumpStreamHandler(stream)); exec.execute(cmd); return FileUtils.readFileToString(logFile); } catch (ExecuteException e) { throw new ExecuteException(e.getMessage(), e.getExitValue(), new RuntimeException(FileUtils.readFileToString(logFile))); } finally { FileUtils.deleteQuietly(logFile); FileUtils.deleteQuietly(scriptFile); } }
From source file:net.gageot.test.utils.Shell.java
/** * Execute an external command.//from w w w . ja v a2s . c o m * * @return exitCode or -1 if an exception occured */ public int execute(String command, Object... arguments) { DefaultExecutor executor = new DefaultExecutor(); CommandLine commandLine = CommandLine.parse(format(command, arguments)); try { return executor.execute(commandLine); } catch (IOException e) { return -1; } }
From source file:com.nts.alphamale.shell.AdbShellExecutor.java
/** * @param cmd adb /*from www.j av a2s . c o m*/ * @param synch ? ? true: synchronous, false: asynchronous * @param (ms) * @return Executor Standard Output? Map */ public int execute(CommandLine cmd, int exitValue) { int rtnValue = -1; DefaultExecutor executor = new DefaultExecutor(); executor.setExitValue(exitValue); try { rtnValue = executor.execute(cmd); } catch (Exception e) { log.error(e.getCause() + ":" + e.getMessage() + "[" + cmd + "]"); } return rtnValue; }
From source file:com.github.brandtg.pantopod.tor.TorProxyManager.java
@Override public void start() throws Exception { synchronized (sync) { File dataDir = new File(torRootDir, String.format("tor_%d", socksPort)); pidFile = new File(dataDir, PID_FILE_NAME); if (pidFile.exists()) { LOG.info("Stopping existing process {}", pidFile); stopProcess(pidFile, 2 /* SIGINT */); }// w ww .jav a 2 s . c o m LOG.info("Creating {}", dataDir); FileUtils.forceMkdir(dataDir); String command = torExecutable + " --RunAsDaemon 1" + " --CookieAuthentication 0" + " --HashedControlPassword \"\"" + " --ControlPort " + controlPort + " --PidFile " + pidFile.getAbsolutePath() + " --SocksPort " + socksPort + " --DataDirectory " + dataDir.getAbsolutePath(); LOG.info("Executing {}", command); DefaultExecutor executor = new DefaultExecutor(); int retCode = executor.execute(CommandLine.parse(command)); LOG.info("Executed {} #=> {}", command, retCode); // Set the system socket proxy System.setProperty("socksProxyHost", "localhost"); System.setProperty("socksProxyPort", String.valueOf(socksPort)); // Schedule a watchdog to periodically send SIGHUP, which resets the tor circuit if (watchdogDelayMillis > 0) { scheduler.schedule(new SigHupWatchdog(pidFile), watchdogDelayMillis, TimeUnit.MILLISECONDS); } } }
From source file:com.virtualparadigm.packman.processor.JPackageManagerBU.java
public static boolean autorun(File autorunDir) { logger.info("PackageManager::autorun()"); boolean status = true; if (autorunDir != null && autorunDir.isDirectory()) { File[] autorunFiles = autorunDir.listFiles(); Arrays.sort(autorunFiles); String fileExtension = null; DefaultExecutor cmdExecutor = new DefaultExecutor(); for (File autorunFile : autorunFiles) { if (!autorunFile.isDirectory()) { try { fileExtension = FilenameUtils.getExtension(autorunFile.getAbsolutePath()); if (fileExtension != null) { if (fileExtension.equalsIgnoreCase("bat") || fileExtension.equalsIgnoreCase("sh")) { logger.info(" executing autorun file: " + autorunFile.getAbsolutePath()); cmdExecutor.execute(CommandLine.parse(autorunFile.getAbsolutePath())); } else if (fileExtension.equalsIgnoreCase("sql") || fileExtension.equalsIgnoreCase("ddl")) { logger.info(" executing autorun file: " + autorunFile.getAbsolutePath()); } else if (fileExtension.equalsIgnoreCase("jar")) { logger.info(" executing autorun file: " + autorunFile.getAbsolutePath()); }/*from www . j av a 2 s . c o m*/ } } catch (Exception e) { logger.error("", e); e.printStackTrace(); } } } } return status; }