Example usage for org.apache.commons.exec ExecuteException printStackTrace

List of usage examples for org.apache.commons.exec ExecuteException printStackTrace

Introduction

In this page you can find the example usage for org.apache.commons.exec ExecuteException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:org.apache.drill.exec.client.DrillClient.java

/**
 * Run external script//  ww w  .jav a 2 s.  com
 *
 * @param command
 */
public void runScript(String command) {
    //System.out.println("RUNNING COMMAND: " + command);
    String sCommandString = command;
    CommandLine oCmdLine = CommandLine.parse(sCommandString);
    DefaultExecutor oDefaultExecutor = new DefaultExecutor();
    oDefaultExecutor.setExitValue(0);
    try {
        int iExitValue = oDefaultExecutor.execute(oCmdLine);
    } catch (ExecuteException e) {
        System.err.println("Execution failed.");
        e.printStackTrace();
    } catch (IOException e) {
        System.err.println("permission denied.");
        e.printStackTrace();
    }
}

From source file:org.apache.zeppelin.submarine.SubmarineJobTest.java

@Test
public void defaultExecutorTest() throws IOException {
    DefaultExecutor executor = new DefaultExecutor();
    CommandLine cmdLine = CommandLine.parse(shell);

    URL urlTemplate = Resources.getResource(DEFAULT_EXECUTOR_TEST);

    cmdLine.addArgument(urlTemplate.getFile(), false);

    Map<String, String> env = new HashMap<>();
    env.put("CLASSPATH", "`$HADOOP_HDFS_HOME/bin/hadoop classpath --glob`");
    env.put("EVN", "test");

    AtomicBoolean cmdLineRunning = new AtomicBoolean(true);
    StringBuffer sbLogOutput = new StringBuffer();
    executor.setStreamHandler(new PumpStreamHandler(new LogOutputStream() {
        @Override//from ww  w.  ja  v  a2  s.  com
        protected void processLine(String line, int level) {
            //LOGGER.info(line);
            sbLogOutput.append(line + "\n");
        }
    }));

    executor.execute(cmdLine, env, new DefaultExecuteResultHandler() {
        @Override
        public void onProcessComplete(int exitValue) {
            cmdLineRunning.set(false);
        }

        @Override
        public void onProcessFailed(ExecuteException e) {
            cmdLineRunning.set(false);
            LOGGER.error(e.getMessage());
        }
    });
    int loopCount = 100;
    while ((loopCount-- > 0) && cmdLineRunning.get()) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    LOGGER.info(sbLogOutput.toString());
}

From source file:org.dataconservancy.dcs.access.server.util.VivoUtil.java

public static String cmdExec(String query, String sparqlEndpoint) {
    String cmd = "curl -s -S -X POST --data-binary \"" + query + "\" " + sparqlEndpoint;
    CommandLine cmdLine = CommandLine.parse(cmd);
    DefaultExecutor executor = new DefaultExecutor();
    ByteArrayOutputStream stdout = new ByteArrayOutputStream();
    PumpStreamHandler psh = new PumpStreamHandler(stdout);

    executor.setStreamHandler(psh);//from  w  w  w .  j ava  2  s .  co m

    int exitValue;
    try {
        exitValue = executor.execute(cmdLine);
    } catch (ExecuteException e) {
        //logger.log(Level.SEVERE, e.getMessage());
        e.printStackTrace();
    } catch (IOException e) {
        //.log(Level.SEVERE, e.getMessage());
        e.printStackTrace();
    }

    //String str = "";
    BufferedReader br = null;
    try {
        br = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(stdout.toByteArray())));
    } catch (Exception e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    String output_line = null;
    String xml = "";
    try {
        int flag = 0;

        while ((output_line = br.readLine()) != null) {
            if (output_line.contains("--:--")) {
                if (output_line.contains("<?xml version"))
                    output_line = output_line.substring(output_line.indexOf("<?xml version"));
                else
                    continue;
            }
            xml += output_line;

        }

    } catch (IOException e) {
        //logger.log(Level.SEVERE, e.getMessage());
        e.printStackTrace();
    }
    return xml;
}

From source file:org.excalibur.service.aws.CommandExample.java

public static void main(String[] args) throws ExecuteException, IOException, InterruptedException {
    CommandLine command = new CommandLine("/bin/bash");
    command.addArgument("-c", false);
    command.addArgument("iperf3 -t 30 -c iperf.scottlinux.com >> output.txt", false);

    //Process process = Runtime.getRuntime().exec(new String[]{"bash", "-c", "iperf3 -t 60 -c localhost"});
    // System.out.println(new Mirror().on(process).get().field("pid"));

    //process.waitFor();

    //        System.out.println(process.exitValue());
    //        ManagementFactory.getRuntimeMXBean().getName();  
    //        System.out.println(IOUtils.readLines(process.getInputStream()));

    //String command = "iperf3 -t 30 -c iperf.scottlinux.com";

    ExecuteWatchdog watchdog = new ExecuteWatchdog(10);

    final DefaultExecutor executor = new DefaultExecutor();
    executor.setStreamHandler(new PumpStreamHandler());
    executor.setExitValue(1);/*ww  w .  j  ava 2  s  .  com*/

    executor.execute(command, new ExecuteResultHandler() {
        @Override
        public void onProcessFailed(ExecuteException e) {
            e.printStackTrace();
        }

        @Override
        public void onProcessComplete(int exitValue) {
            System.out.println(exitValue);
        }
    });
}

From source file:org.kercoin.magrit.core.build.BuildTask.java

private void gnomeNotifySend(int exitCode, boolean success) {
    try {//  w w  w. jav a2s .com
        String message = "";
        if (success) {
            message = String.format("notify-send \"Magrit\" \"Build successful\"");
        } else {
            message = String.format("notify-send \"Magrit\" \"Build failed %s\"", exitCode);
        }
        new DefaultExecutor().execute(CommandLine.parse(message));
    } catch (ExecuteException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:util.Utility.java

/**
 * command line execution/*from  ww w .  ja v a 2 s. c o m*/
 * 
 * @param line command line
 * @return output string of running this command line
 */
public static String exec(String line) {

    //String line = "wc -l " + "/home/hathitrust/solr/ToVM_Solr_related/test/apache-tomcat-6.0.35/bin/proxy_logs/logfile";

    CommandLine command = CommandLine.parse(line);

    DefaultExecutor executor = new DefaultExecutor();

    //int exitValue = executor.execute(command);

    ByteArrayOutputStream stdout = new ByteArrayOutputStream();
    PumpStreamHandler pump_stream_handler = new PumpStreamHandler(stdout);

    executor.setStreamHandler(pump_stream_handler);

    int exitValue = 0;
    try {
        exitValue = executor.execute(command);
    } catch (ExecuteException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    // System.out.println(exitValue);

    // System.out.println(stdout.toString());

    return stdout.toString();

}