Package org.apache.commons.exec

Examples of org.apache.commons.exec.CommandLine


            return exec(cmd, env);
        }

        // Use cmd.exe to change to the specified directory before running
        // the command
        CommandLine newCmd = new CommandLine("cmd");
        newCmd.addArgument("/c");
        newCmd.addArguments(cmd.toStrings());

        return exec(newCmd, env);
    }
View Full Code Here


        // handle error and output of the process and write them to the given
        // out stream
        PumpStreamHandler handler = new PumpStreamHandler(out, err, command.getInput());
        executor.setStreamHandler(handler);

        CommandLine cl = toCommandLine(command);

        try {
            int exitValue = executor.execute(cl);
            // if the size is zero, we have no output, so construct the result
            // with null (required by ExecResult)
View Full Code Here

     * @param execCommand a not-null <code>ExecCommand</code> instance.
     * @return a {@link CommandLine} object.
     */
    protected CommandLine toCommandLine(ExecCommand execCommand) {
        notNull(execCommand, "execCommand");
        CommandLine cl = new CommandLine(execCommand.getExecutable());
        List<String> args = execCommand.getArgs();
        for (String arg : args) {
            // do not handle quoting here, it is already quoted
            cl.addArgument(arg, false);
        }
        return cl;
    }
View Full Code Here

        // Only run for N milliseconds
        int timeout = appConf.getInt(AppConfig.EXEC_TIMEOUT_NAME, 0);
        ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout);
        executor.setWatchdog(watchdog);

        CommandLine cmd = makeCommandLine(program, args);

        LOG.info("Running: " + cmd);
        ExecBean res = new ExecBean();
        res.exitcode = executor.execute(cmd, execEnv(env));
        String enc = appConf.get(AppConfig.EXEC_ENCODING_NAME);
View Full Code Here

    private CommandLine makeCommandLine(String program,
                                        List<String> args)
        throws NotAuthorizedException, IOException {
        String path = validateProgram(program);
        CommandLine cmd = new CommandLine(path);
        if (args != null)
            for (String arg : args)
                cmd.addArgument(arg, false);

        return cmd;
    }
View Full Code Here

                getLog().info("GWT files are up to date. Skipping GWT build.");
                return;
            }
        }
       
        CommandLine cmd = new CommandLine("java");
        ClassBuilder cb = new ClassBuilder(project);
       
        cb.add(p.getProperty("spiffyui.generated-source"));
        cb.add(resources.getAbsolutePath());

        for (String sourceRoot : compileSourceRoots) {
            cb.add(sourceRoot);
        }
       
        cmd.addArgument("-cp").addArgument(cb.toString())
            .addArgument(extraJvmArgs)
            .addArgument("com.google.gwt.dev.Compiler")
            .addArgument("-gen").addArgument(gen.getAbsolutePath())
            .addArgument("-logLevel").addArgument(logLevel)
            .addArgument("-style").addArgument(style)
            .addArgument("-war").addArgument(outputDirectory.getAbsolutePath())
            .addArgument("-localWorkers").addArgument(String.valueOf(getLocalWorkers()));
       
        // optional advanced arguments
        if (enableAssertions) {
            cmd.addArgument("-ea");
        }
       
        if (draftCompile) {
            cmd.addArgument("-draftCompile");
        }
        if (validateOnly) {
            cmd.addArgument("-validateOnly");
        }
       
        if (treeLogger) {
            cmd.addArgument("-treeLogger");
        }
       
        if (disableClassMetadata) {
            cmd.addArgument("-XdisableClassMetadata");
        }
       
        if (disableCastChecking) {
            cmd.addArgument("-XdisableCastChecking");
        }
       
        if (strict) {
            cmd.addArgument("-strict");
        }
       
        if (soycDetailed) {
            cmd.addArgument("-XsoycDetailed");
        }
        if (optimizationLevel >= 0) {
            cmd.addArgument("-optimize").addArgument(Integer.toString(optimizationLevel));
        }

        if (extraParam || compileReport) {
            getLog().debug("create extra directory ");
            if (!extra.exists()) {
                extra.mkdirs();
            }
            cmd.addArgument("-extra").addArgument(extra.getAbsolutePath());
        } else {
            getLog().debug("NOT create extra directory ");
        }

        if (compileReport) {
            cmd.addArgument("-compileReport");
        }

        if (workDir != null) {
            cmd.addArgument("-workDir").addArgument(String.valueOf(workDir));
        }
       
        cmd.addArgument(gwtModuleName);
               
        try {
            DefaultExecutor executor = new DefaultExecutor();

            getLog().debug("Exec: " + cmd.toString());

            int ret = executor.execute(cmd, CommandLineUtils.getSystemEnvVars());
            if (ret != 0) {
                throw new MojoExecutionException("Exec failed: " + Integer.toString(ret));
            }
View Full Code Here

  }

  private static String execute(String commandLine) throws ExecuteException, IOException {
    ByteArrayOutputStream stdout = new ByteArrayOutputStream();
    PumpStreamHandler psh = new PumpStreamHandler(stdout);
    CommandLine cl = CommandLine.parse("/bin/bash " + commandLine);
    DefaultExecutor exec = new DefaultExecutor();
    exec.setWorkingDirectory(PROJECT_BASE_DIR);
    exec.setStreamHandler(psh);
    try {
      exec.execute(cl, env);
View Full Code Here

    }
   
    Executor executor = new DefaultExecutor();
        executor.setWorkingDirectory(site.getParentFile());

        CommandLine command = CommandLine.parse(execCommand);
       
        out.println("========================");
        info(out, String.format("Execute command: %s",  command.toString()));
        out.println("========================");
        LogOutputStream outputStream = new LogOutputStream() {
            protected void processLine(String line, int level){
                log.info(String.format("Command logged an out: %s", line));
                out.println(line);
View Full Code Here

     * variables.
     *
     * @return the command line
     */   
    protected CommandLine getProcEnvCommand() {
        CommandLine commandLine = new CommandLine("show");
        commandLine.addArgument("symbol/global"); // the parser assumes symbols are global
        commandLine.addArgument("*");
        return commandLine;
    }
View Full Code Here

        } else {
            // MAC OS 9 and previous
            // TODO: I have no idea how to get it, someone must fix it
            executable = null;
        }
        CommandLine commandLine = null;
        if(executable != null) {
            commandLine = new CommandLine(executable);
            commandLine.addArguments(arguments);
        }
        return commandLine;
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.exec.CommandLine

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.