List of usage examples for org.apache.commons.exec ExecuteException printStackTrace
public void printStackTrace()
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 www . ja v a 2 s .c om*/ 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:com.mooregreatsoftware.gitprocess.lib.Pusher.java
private static ThePushResult doGitProgPush(GitLib gitLib, Branch localBranch, String remoteBranchName, boolean forcePush, String remoteName) { String cmd = String.format("git push --porcelain %s %s %s:%s", remoteName, forcePush ? "--force" : "", localBranch.shortName(), remoteBranchName); CommandLine commandLine = CommandLine.parse(cmd); DefaultExecutor executor = new DefaultExecutor(); executor.setWorkingDirectory(gitLib.workingDirectory()); final StringWriter stdOutWriter = new StringWriter(); final StringWriter stdErrWriter = new StringWriter(); executor.setStreamHandler(/* w ww.j a va 2 s . c o m*/ new PumpStreamHandler(new WriterOutputStream(stdOutWriter), new WriterOutputStream(stdErrWriter))); final int exitCode = Try.of(() -> { try { return executor.execute(commandLine); } catch (ExecuteException e) { return e.getExitValue(); } catch (IOException e) { final String message = e.getMessage(); if (message != null && message.contains("No such file or directory")) { return 1; } e.printStackTrace(); return -1; } }).get(); return new ProcPushResult(stdOutWriter, stdErrWriter, exitCode); }
From source file:com.demandware.vulnapp.challenge.impl.CommandInjectionChallenge.java
private String getCommandOutput(String command) { String output = null;/*from w ww . j a va 2s . 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:it.drwolf.ridire.utility.RIDIREReTagger.java
public RIDIREReTagger(String[] args) { if (args != null) { this.createOptions(); this.parseOptions(args); File[] files = this.getPlainTextFiles(); for (File f : files) { System.out.print("Retagging file: " + f.getName() + "..."); try { this.retagFile(f); } catch (ExecuteException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace();//from w ww .j ava 2 s . co m } System.out.println(" done."); } } }
From source file:de.tu_dresden.psy.fca.ConexpCljBridge.java
public ConexpCljBridge() { this.b = new byte[1]; /**//from w w w . ja v a 2 s .c om * build the command line (see conexp-clj/bin/conexp-clj) */ String java_bin = Launcher.getJavaCommand(); CommandLine conexp_cmd = new CommandLine(java_bin); conexp_cmd.addArgument("-server"); conexp_cmd.addArgument("-cp"); conexp_cmd.addArgument("./conexp-clj/lib/conexp-clj-0.0.7-alpha-SNAPSHOT-standalone.jar"); conexp_cmd.addArgument("clojure.main"); conexp_cmd.addArgument("-e"); conexp_cmd.addArgument(""); conexp_cmd.addArgument("./conexp-clj/lib/conexp-clj.clj"); /** * open the pipes */ this.to_conexp = new PipedOutputStream(); try { this.stream_to_conexp = new PipedInputStream(this.to_conexp, 2048); } catch (IOException e2) { e2.printStackTrace(); } this.stream_error_conexp = new PipedOutputStream(); this.stream_from_conexp = new PipedOutputStream(); try { this.from_conexp = new PipedInputStream(this.stream_from_conexp, 2048); } catch (IOException e1) { e1.printStackTrace(); } try { this.error_conexp = new PipedInputStream(this.stream_error_conexp, 2048); } catch (IOException e1) { e1.printStackTrace(); } /** * setup apache commons exec */ this.result = new DefaultExecuteResultHandler(); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValue(0); executor.setStreamHandler( new PumpStreamHandler(this.stream_from_conexp, this.stream_error_conexp, this.stream_to_conexp)); /** * run in non-blocking mode */ try { executor.execute(conexp_cmd, this.result); } catch (ExecuteException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } this.output_buffer = ""; }
From source file:gr.upatras.ece.nam.baker.impl.InstalledBunLifecycleMgmt.java
public int executeSystemCommand(String cmdStr) { logger.info(" ================> Execute :" + 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 ww w.j av a2 s.c o m ByteArrayOutputStream out = new ByteArrayOutputStream(); PumpStreamHandler streamHandler = new PumpStreamHandler(out); executor.setStreamHandler(streamHandler); int exitValue = -1; try { exitValue = executor.execute(cmdLine); logger.info(" ================> EXIT (" + exitValue + ") FROM :" + cmdStr); } catch (ExecuteException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } logger.info("out>" + out); return exitValue; }
From source file:de.woq.osgi.java.itestsupport.ContainerRunner.java
public synchronized void start() throws Exception { started.set(true);/*from w w w .ja va2 s. co m*/ Runnable runner = new Runnable() { @Override public void run() { try { String command = getContainerCommand(); String script = findContainerDirectory() + "/bin/" + command; LOGGER.info("Using Container start command [{}] with profile [{}].", command, profile); LOGGER.info("Start script is [{}].", script); CommandLine cl = new CommandLine(script).addArguments(profile); executor.execute(cl, new ExecuteResultHandler() { @Override public void onProcessComplete(int exitValue) { latch.countDown(); } @Override public void onProcessFailed(ExecuteException e) { latch.countDown(); } }); } catch (Exception e) { e.printStackTrace(); } } }; new Thread(runner).start(); }
From source file:llc.rockford.webcast.EC2Driver.java
public Component createComponents() { startButton = new JButton("START SERVER"); startButton.setEnabled(false);//w ww . ja v a 2 s.co m startButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { startButton.setEnabled(false); stopButton.setEnabled(false); new StartInstanceWorker(ec2Handle.getEc2Handle(), applicationState, amazonProperties).execute(); } }); startStreamButton = new JButton("START BROADCAST"); startStreamButton.setEnabled(false); startStreamButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { startStreamButton.setEnabled(false); stopStreamButton.setEnabled(true); try { broadcaster.start(); } catch (ExecuteException e1) { startStreamButton.setEnabled(true); e1.printStackTrace(); } catch (IOException e1) { startStreamButton.setEnabled(true); e1.printStackTrace(); } catch (InterruptedException e1) { e1.printStackTrace(); } } }); stopStreamButton = new JButton("STOP BROADCAST"); stopStreamButton.setEnabled(false); stopStreamButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { broadcaster.stop(); } }); statusLabel.setHorizontalAlignment(SwingConstants.CENTER); statusLabel.setOpaque(true); statusLabel.setBackground(Color.YELLOW); broadcastStatusLabel.setHorizontalAlignment(SwingConstants.CENTER); broadcastStatusLabel.setOpaque(true); broadcastStatusLabel.setBackground(Color.RED); stopButton = new JButton("STOP SERVER"); stopButton.setEnabled(false); stopButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { startButton.setEnabled(false); stopButton.setEnabled(false); new TerminateInstanceWorker(ec2Handle.getEc2Handle(), applicationState, amazonProperties).execute(); } }); JPanel pane = new JPanel(new GridLayout(7, 1)); pane.add(startButton); pane.add(statusLabel); pane.add(stopButton); pane.add(new JSeparator(SwingConstants.HORIZONTAL)); pane.add(startStreamButton); pane.add(broadcastStatusLabel); pane.add(stopStreamButton); pane.setBorder(BorderFactory.createEmptyBorder(30, // top 30, // left 10, // bottom 30) // right ); return pane; }
From source file:it.drwolf.ridire.index.cwb.scripts.VRTFilesBuilder.java
@SuppressWarnings("unchecked") @Asynchronous/*from w ww .jav a2 s . co m*/ public void retagFiles(VRTFilesBuilderData vrtFilesBuilderData) { String destDir = vrtFilesBuilderData.getDestDir(); StrTokenizer strTokenizer = new StrTokenizer("\t"); this.ridirePlainTextCleaner = new RIDIREPlainTextCleaner(null); this.ridireReTagger = new RIDIREReTagger(null); this.entityManager = (EntityManager) Component.getInstance("entityManager"); this.userTx = (UserTransaction) org.jboss.seam.Component .getInstance("org.jboss.seam.transaction.transaction"); try { this.userTx.setTransactionTimeout(1000 * 10 * 60); if (!this.userTx.isActive()) { this.userTx.begin(); } this.entityManager.joinTransaction(); String treeTaggerBin = this.entityManager .find(CommandParameter.class, CommandParameter.TREETAGGER_EXECUTABLE_KEY).getCommandValue(); this.ridireReTagger.setTreetaggerBin(treeTaggerBin); this.entityManager.flush(); this.entityManager.clear(); this.userTx.commit(); String strangeFilesList = vrtFilesBuilderData.getOrigDir(); File strangeFilesListFile = new File(strangeFilesList); if (strangeFilesListFile.exists() && strangeFilesListFile.canRead()) { List<String> posFilesName = FileUtils.readLines(strangeFilesListFile); int count = 0; int size = posFilesName.size(); for (String posFName : posFilesName) { String digest = FilenameUtils.getBaseName(posFName.trim()).replaceAll(".txt", ""); if (this.vrtFileExists(destDir, digest)) { System.out.println("Skipping: " + digest); continue; } if (!this.userTx.isActive()) { this.userTx.begin(); } this.entityManager.joinTransaction(); List<CrawledResource> crs = this.entityManager .createQuery("from CrawledResource cr where cr.digest=:digest") .setParameter("digest", digest).getResultList(); if (crs != null && crs.size() > 0) { CrawledResource cr = crs.get(0); File fToBeCleaned = new File(posFName.trim().replace(".pos", "")); try { this.ridirePlainTextCleaner.cleanTextFile(fToBeCleaned); this.ridireReTagger.retagFile(fToBeCleaned); if (fToBeCleaned != null) { Integer wordsNumber = Mapper .countWordsFromPoSTagResource(fToBeCleaned.getAbsolutePath()); cr.setWordsNumber(wordsNumber); this.entityManager.persist(cr); this.createVRTFile(posFName.trim(), strTokenizer, cr, new File(destDir)); } } catch (ExecuteException ee) { ee.printStackTrace(); } } this.entityManager.flush(); this.entityManager.clear(); this.userTx.commit(); ++count; if (count % 100 == 0) { System.out.println("Retagging: " + count + " of " + size); } } } } catch (SystemException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NotSupportedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (RollbackException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (HeuristicMixedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (HeuristicRollbackException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { try { if (this.userTx != null && this.userTx.isActive()) { this.userTx.rollback(); } } catch (IllegalStateException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (SecurityException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (SystemException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } System.out.println("Retagging done."); }
From source file:org.apache.bigtop.itest.hive.HiveHelper.java
public static Map<String, String> execCommand(CommandLine commandline, Map<String, String> envVars) { System.out.println("Executing command:"); System.out.println(commandline.toString()); Map<String, String> env = null; Map<String, String> entry = new HashMap<String, String>(); try {//from ww w .j a va2 s . c om env = EnvironmentUtils.getProcEnvironment(); } catch (IOException e1) { // TODO Auto-generated catch block LOG.debug("Failed to get process environment: " + e1.getMessage()); e1.printStackTrace(); } if (envVars != null) { for (String key : envVars.keySet()) { env.put(key, envVars.get(key)); } } DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream); ExecuteWatchdog watchdog = new ExecuteWatchdog(60 * 10000); Executor executor = new DefaultExecutor(); executor.setExitValue(1); executor.setWatchdog(watchdog); executor.setStreamHandler(streamHandler); try { executor.execute(commandline, env, resultHandler); } catch (ExecuteException e) { // TODO Auto-generated catch block LOG.debug("Failed to execute command with exit value: " + String.valueOf(resultHandler.getExitValue())); LOG.debug("outputStream: " + outputStream.toString()); entry.put("exitValue", String.valueOf(resultHandler.getExitValue())); entry.put("outputStream", outputStream.toString() + e.getMessage()); e.printStackTrace(); return entry; } catch (IOException e) { // TODO Auto-generated catch block LOG.debug("Failed to execute command with exit value: " + String.valueOf(resultHandler.getExitValue())); LOG.debug("outputStream: " + outputStream.toString()); entry.put("exitValue", String.valueOf(resultHandler.getExitValue())); entry.put("outputStream", outputStream.toString() + e.getMessage()); e.printStackTrace(); return entry; } try { resultHandler.waitFor(); /*System.out.println("Command output: "+outputStream.toString());*/ entry.put("exitValue", String.valueOf(resultHandler.getExitValue())); entry.put("outputStream", outputStream.toString()); return entry; } catch (InterruptedException e) { // TODO Auto-generated catch block /*System.out.println("Command output: "+outputStream.toString());*/ LOG.debug("exitValue: " + String.valueOf(resultHandler.getExitValue())); LOG.debug("outputStream: " + outputStream.toString()); entry.put("exitValue", String.valueOf(resultHandler.getExitValue())); entry.put("outputStream", outputStream.toString()); e.printStackTrace(); return entry; } }