List of usage examples for org.apache.commons.exec DefaultExecutor execute
public int execute(final CommandLine command) throws ExecuteException, IOException
From source file:org.apache.storm.util.CoreUtil.java
@ClojureClass(className = "backtype.storm.util#exec-command!") public static void execCommand(String command) throws ExecuteException, IOException { String[] cmdlist = command.split(" "); CommandLine cmd = new CommandLine(cmdlist[0]); for (int i = 1; i < cmdlist.length; i++) { cmd.addArgument(cmdlist[i]);// ww w .jav a 2 s . co m } DefaultExecutor exec = new DefaultExecutor(); exec.execute(cmd); }
From source file:org.apache.storm.utils.ServerUtils.java
public static int execCommand(String... command) throws ExecuteException, IOException { CommandLine cmd = new CommandLine(command[0]); for (int i = 1; i < command.length; i++) { cmd.addArgument(command[i]);/*from w w w .ja va 2 s . c o m*/ } DefaultExecutor exec = new DefaultExecutor(); return exec.execute(cmd); }
From source file:org.apache.stratos.integration.tests.SampleApplicationsTest.java
/** * Execute shell command/*from w w w . j a v a 2 s. com*/ * @param commandText */ private void executeCommand(String commandText) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try { CommandLine commandline = CommandLine.parse(commandText); DefaultExecutor exec = new DefaultExecutor(); PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream); exec.setStreamHandler(streamHandler); exec.execute(commandline); log.info(outputStream.toString()); } catch (Exception e) { log.error(outputStream.toString(), e); throw new RuntimeException(e); } }
From source file:org.apache.stratos.integration.tests.SampleApplicationTests.java
private void executeCommand(String commandText) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try {// ww w . j av a 2 s. c o m CommandLine commandline = CommandLine.parse(commandText); DefaultExecutor exec = new DefaultExecutor(); PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream); exec.setStreamHandler(streamHandler); exec.execute(commandline); log.info(outputStream.toString()); } catch (Exception e) { log.error(outputStream.toString(), e); throw new RuntimeException(e); } }
From source file:org.apache.tika.parser.ocr.TesseractOCRParser.java
/** * This method is used to process the image to an OCR-friendly format. * @param streamingObject input image to be processed * @param config TesseractOCRconfig class to get ImageMagick properties * @throws IOException if an input error occurred * @throws TikaException if an exception timed out *///from w ww . ja v a2 s . co m private void processImage(File streamingObject, TesseractOCRConfig config) throws IOException, TikaException { // fetch rotation script from resources InputStream in = getClass().getResourceAsStream("rotation.py"); TemporaryResources tmp = new TemporaryResources(); File rotationScript = tmp.createTemporaryFile(); Files.copy(in, rotationScript.toPath(), StandardCopyOption.REPLACE_EXISTING); String cmd = "python " + rotationScript.getAbsolutePath() + " -f " + streamingObject.getAbsolutePath(); String angle = "0"; DefaultExecutor executor = new DefaultExecutor(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream); executor.setStreamHandler(streamHandler); // determine the angle of rotation required to make the text horizontal CommandLine cmdLine = CommandLine.parse(cmd); if (hasPython()) { try { executor.execute(cmdLine); angle = outputStream.toString("UTF-8").trim(); } catch (Exception e) { } } // process the image - parameter values can be set in TesseractOCRConfig.properties String line = "convert -density " + config.getDensity() + " -depth " + config.getDepth() + " -colorspace " + config.getColorspace() + " -filter " + config.getFilter() + " -resize " + config.getResize() + "% -rotate " + angle + " " + streamingObject.getAbsolutePath() + " " + streamingObject.getAbsolutePath(); cmdLine = CommandLine.parse(line); try { executor.execute(cmdLine); } catch (Exception e) { } tmp.close(); }
From source file:org.apache.zeppelin.interpreter.launcher.Kubectl.java
public int execute(String[] args, InputStream stdin, OutputStream stdout, OutputStream stderr) throws IOException { DefaultExecutor executor = new DefaultExecutor(); CommandLine cmd = new CommandLine(kubectlCmd); cmd.addArguments(args);/*w w w. j av a 2 s . c o m*/ ExecuteWatchdog watchdog = new ExecuteWatchdog(60 * 1000); executor.setWatchdog(watchdog); PumpStreamHandler streamHandler = new PumpStreamHandler(stdout, stderr, stdin); executor.setStreamHandler(streamHandler); return executor.execute(cmd); }
From source file:org.apache.zeppelin.shell.security.ShellSecurityImpl.java
public static void createSecureConfiguration(Properties properties, String shell) { String authType = properties.getProperty("zeppelin.shell.auth.type").trim().toUpperCase(); switch (authType) { case "KERBEROS": CommandLine cmdLine = CommandLine.parse(shell); cmdLine.addArgument("-c", false); String kinitCommand = String.format("kinit -k -t %s %s", properties.getProperty("zeppelin.shell.keytab.location"), properties.getProperty("zeppelin.shell.principal")); cmdLine.addArgument(kinitCommand, false); DefaultExecutor executor = new DefaultExecutor(); try {/*from w ww . j ava2 s.c om*/ int exitVal = executor.execute(cmdLine); } catch (Exception e) { LOGGER.error("Unable to run kinit for zeppelin user " + kinitCommand, e); throw new InterpreterException(e); } } }
From source file:org.apache.zeppelin.shell.ShellInterpreter.java
@Override public InterpreterResult interpret(String cmd, InterpreterContext contextInterpreter) { logger.debug("Run shell command '" + cmd + "'"); long start = System.currentTimeMillis(); CommandLine cmdLine = CommandLine.parse("bash"); cmdLine.addArgument("-c", false); cmdLine.addArgument(cmd, false);// w w w . j a v a 2s. c om DefaultExecutor executor = new DefaultExecutor(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); executor.setStreamHandler(new PumpStreamHandler(outputStream)); executor.setWatchdog(new ExecuteWatchdog(commandTimeOut)); try { int exitValue = executor.execute(cmdLine); return new InterpreterResult(InterpreterResult.Code.SUCCESS, outputStream.toString()); } catch (ExecuteException e) { logger.error("Can not run " + cmd, e); return new InterpreterResult(Code.ERROR, e.getMessage()); } catch (IOException e) { logger.error("Can not run " + cmd, e); return new InterpreterResult(Code.ERROR, e.getMessage()); } }
From source file:org.apache.zeppelin.submarine.SubmarineShellInterpreter.java
public void createSecureConfiguration() throws InterpreterException { Properties properties = getProperties(); CommandLine cmdLine = CommandLine.parse(shell); cmdLine.addArgument("-c", false); String kinitCommand = String.format("kinit -k -t %s %s", properties.getProperty(SUBMARINE_HADOOP_KEYTAB), properties.getProperty(SUBMARINE_HADOOP_PRINCIPAL)); cmdLine.addArgument(kinitCommand, false); DefaultExecutor executor = new DefaultExecutor(); try {//w ww. ja v a 2 s. c o m executor.execute(cmdLine); } catch (Exception e) { LOGGER.error("Unable to run kinit for zeppelin user " + kinitCommand, e); throw new InterpreterException(e); } }
From source file:org.atmosphere.vibe.ProtocolTest.java
@Test public void protocol() throws Exception { final DefaultServer server = new DefaultServer(); server.onsocket(new Action<ServerSocket>() { @Override/*from ww w . j a va 2s. c o m*/ public void on(final ServerSocket socket) { socket.on("abort", new VoidAction() { @Override public void on() { socket.close(); } }).on("echo", new Action<Object>() { @Override public void on(Object data) { socket.send("echo", data); } }).on("/reply/inbound", new Action<Reply<Map<String, Object>>>() { @Override public void on(Reply<Map<String, Object>> reply) { Map<String, Object> data = reply.data(); switch ((String) data.get("type")) { case "resolved": reply.resolve(data.get("data")); break; case "rejected": reply.reject(data.get("data")); break; } } }).on("/reply/outbound", new Action<Map<String, Object>>() { @Override public void on(Map<String, Object> data) { switch ((String) data.get("type")) { case "resolved": socket.send("test", data.get("data"), new Action<Object>() { @Override public void on(Object data) { socket.send("done", data); } }); break; case "rejected": socket.send("test", data.get("data"), null, new Action<Object>() { @Override public void on(Object data) { socket.send("done", data); } }); break; } } }); } }); final HttpTransportServer httpTransportServer = new HttpTransportServer().ontransport(server); final WebSocketTransportServer wsTransportServer = new WebSocketTransportServer().ontransport(server); org.eclipse.jetty.server.Server jetty = new org.eclipse.jetty.server.Server(); ServerConnector connector = new ServerConnector(jetty); connector.setPort(8000); jetty.addConnector(connector); ServletContextHandler handler = new ServletContextHandler(); handler.addEventListener(new ServletContextListener() { @Override @SuppressWarnings("serial") public void contextInitialized(ServletContextEvent event) { ServletContext context = event.getServletContext(); // /setup ServletRegistration regSetup = context.addServlet("/setup", new HttpServlet() { @Override protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { Map<String, String[]> params = req.getParameterMap(); if (params.containsKey("heartbeat")) { server.setHeartbeat(Integer.parseInt(params.get("heartbeat")[0])); } if (params.containsKey("_heartbeat")) { server.set_heartbeat(Integer.parseInt(params.get("_heartbeat")[0])); } } }); regSetup.addMapping("/setup"); // /vibe Servlet servlet = new VibeAtmosphereServlet().onhttp(httpTransportServer) .onwebsocket(wsTransportServer); ServletRegistration.Dynamic reg = context.addServlet(VibeAtmosphereServlet.class.getName(), servlet); reg.setAsyncSupported(true); reg.setInitParameter(ApplicationConfig.DISABLE_ATMOSPHEREINTERCEPTOR, Boolean.TRUE.toString()); reg.addMapping("/vibe"); } @Override public void contextDestroyed(ServletContextEvent sce) { } }); jetty.setHandler(handler); jetty.start(); CommandLine cmdLine = CommandLine.parse("./src/test/resources/node/node") .addArgument("./src/test/resources/runner").addArgument("--vibe.transports") .addArgument("websocket,httpstream,httplongpoll"); DefaultExecutor executor = new DefaultExecutor(); // The exit value of mocha is the number of failed tests. executor.execute(cmdLine); jetty.stop(); }