Example usage for org.apache.commons.exec CommandLine CommandLine

List of usage examples for org.apache.commons.exec CommandLine CommandLine

Introduction

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

Prototype

public CommandLine(final CommandLine other) 

Source Link

Document

Copy constructor.

Usage

From source file:com.kotcrab.vis.editor.Main.java

public static void main(String[] args) throws Exception {
    App.init();/*from   ww w  .ja va 2s  . c om*/
    if (OsUtils.isMac())
        System.setProperty("java.awt.headless", "true");

    LaunchConfiguration launchConfig = new LaunchConfiguration();

    //TODO: needs some better parser
    for (int i = 0; i < args.length; i++) {
        String arg = args[i];
        if (arg.equals("--scale-ui")) {
            launchConfig.scaleUIEnabled = true;
            continue;
        }

        if (arg.equals("--project")) {
            if (i + 1 >= args.length) {
                throw new IllegalStateException("Not enough parameters for --project <project path>");
            }

            launchConfig.projectPath = args[i + 1];
            i++;
            continue;
        }

        if (arg.equals("--scene")) {
            if (i + 1 >= args.length) {
                throw new IllegalStateException("Not enough parameters for --scene <scene path>");
            }

            launchConfig.scenePath = args[i + 1];
            i++;
            continue;
        }

        Log.warn("Unrecognized command line argument: " + arg);
    }

    launchConfig.verify();

    editor = new Editor(launchConfig);

    Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration();
    config.setWindowedMode(1280, 720);
    config.setWindowSizeLimits(1, 1, 9999, 9999);
    config.useVsync(true);
    config.setIdleFPS(2);
    config.setWindowListener(new Lwjgl3WindowAdapter() {
        @Override
        public boolean closeRequested() {
            editor.requestExit();
            return false;
        }
    });

    try {
        new Lwjgl3Application(editor, config);
        Log.dispose();
    } catch (Exception e) {
        Log.exception(e);
        Log.fatal("Uncaught exception occurred, error report will be saved");
        Log.flush();

        if (App.eventBus != null)
            App.eventBus.post(new ExceptionEvent(e, true));

        try {
            File crashReport = new CrashReporter(Log.getLogFile().file()).processReport();
            if (new File(App.TOOL_CRASH_REPORTER_PATH).exists() == false) {
                Log.warn("Crash reporting tool not present, skipping crash report sending.");
            } else {
                CommandLine cmdLine = new CommandLine(PlatformUtils.getJavaBinPath());
                cmdLine.addArgument("-jar");
                cmdLine.addArgument(App.TOOL_CRASH_REPORTER_PATH);
                cmdLine.addArgument(ApplicationUtils.getRestartCommand().replace("\"", "%"));
                cmdLine.addArgument(crashReport.getAbsolutePath(), false);
                DefaultExecutor executor = new DefaultExecutor();
                executor.setStreamHandler(new PumpStreamHandler(null, null, null));
                executor.execute(cmdLine);
            }
        } catch (IOException ex) {
            ex.printStackTrace();
        }

        Log.dispose();
        System.exit(-3);
    } catch (ExceptionInInitializerError err) {
        if (OsUtils.isMac() && err.getCause() instanceof IllegalStateException) {
            if (ExceptionUtils.getStackTrace(err).contains("XstartOnFirstThread")) {
                System.out.println(
                        "Application was not launched on first thread. Restarting with -XstartOnFirstThread, add VM argument -XstartOnFirstThread to avoid this.");
                ApplicationUtils.startNewInstance();
            }
        }

        throw err;
    }
}

From source file:generator.Utils.java

public static boolean exec(String command, File workingDir, String... args) {
    try {//from  w  ww. j ava2  s  .co m
        CommandLine cmdLine = new CommandLine(command);
        cmdLine.addArguments(args, false);
        DefaultExecutor exe = new DefaultExecutor();
        exe.setWorkingDirectory(workingDir);
        return exe.execute(cmdLine) == 0;
    } catch (Exception e) {
        return false;
    }
}

From source file:net.orpiske.sdm.lib.Executable.java

/**
 * Executes a command//  w ww. j av  a 2s . c  om
 * @param command the command to execute
 * @param arguments the arguments to pass to the command
 * @return the return code from the command
 * @throws ExecuteException
 * @throws IOException
 */
public static int exec(final String command, final String arguments) throws ExecuteException, IOException {
    CommandLine cmd = new CommandLine(command);

    cmd.addArguments(arguments);

    DefaultExecutor executor = new DefaultExecutor();

    return executor.execute(cmd);
}

From source file:io.selendroid.android.JavaSdk.java

public static String javaHome() {
    if (javaHome == null) {
        // Sniff JAVA_HOME first
        javaHome = System.getenv("JAVA_HOME");

        // If that's not present, and we're on a Mac...
        if (javaHome == null && Platform.getCurrent() == MAC) {
            try {
                javaHome = ShellCommand.exec(new CommandLine("/usr/libexec/java_home"));
                if (javaHome != null) {
                    javaHome = javaHome.replaceAll("\\r|\\n", "");
                }//from ww  w  .  j  a v a 2s.  c o  m

            } catch (ShellCommandException e) {
            }
        }
        // Finally, check java.home, though this may point to a JRE.
        if (javaHome == null) {
            javaHome = System.getProperty("java.home");
        }
    }
    return javaHome;
}

From source file:com.nts.alphamale.shell.AdbShellCommand.java

/**
 * 1. adbcommand.properties? ? adb command list  ?  ResourceBudle? ?  ??? .
 * 2.  adb  ?  ??? . /*from   w ww .j a  v  a  2  s  . c o m*/
 * @param serial ?? 
 * @param adbCmd adb 
 * @return adb command line
 */
public static CommandLine cmd(String serial, String adbCmd) {
    CommandLine cmd = new CommandLine(Utils.adb());
    if (!serial.isEmpty()) {
        cmd.addArgument("-s");
        cmd.addArgument(serial);
    }
    if (ADB_COMMAND_BUNDLE.getString(adbCmd).isEmpty()) {
        cmd.addArguments(adbCmd.split(" "));
    } else {
        cmd.addArguments(ADB_COMMAND_BUNDLE.getString(adbCmd).split(" "));
    }
    return cmd;
}

From source file:common.UglyLaunchTempPatch.java

/**
 * code for lunching external jar file/*from   ww w  .j a va  2s .c om*/
 * 
 * @param jarFile
 *            the jar file that is being lunched
 * @param Server
 *            is this a server lunch or not
 * @throws IOException
 * @throws ClassNotFoundException
 * @throws NoSuchMethodException
 * @throws InvocationTargetException
 * @throws IllegalAccessException
 * @throws InterruptedException
 */
public static void jar(File jarFile) throws IOException, ClassNotFoundException, NoSuchMethodException,
        InvocationTargetException, IllegalAccessException, InterruptedException {

    Main.print("\"" + jarFile.getAbsolutePath() + "\"");
    // sets jar to deleate on exit of program
    jarFile.deleteOnExit();

    //runs the client version of the forge installer.

    Map map = new HashMap();
    map.put("file", jarFile);
    CommandLine cmdLine = new CommandLine("java");
    cmdLine.addArgument("-jar");
    cmdLine.addArgument("${file}");
    cmdLine.setSubstitutionMap(map);
    DefaultExecutor executor = new DefaultExecutor();
    executor.setExitValue(0);
    ExecuteWatchdog watchdog = new ExecuteWatchdog(60000);
    executor.setWatchdog(watchdog);
    int exitValue = executor.execute(cmdLine);
}

From source file:client.UglyLaunchTempPatch.java

/**
 * code for lunching external jar file/*w w w .  j  a  va2 s  . c  om*/
 * 
 * @param jarFile
 *            the jar file that is being lunched
 * @param Server
 *            is this a server lunch or not
 * @throws IOException
 * @throws ClassNotFoundException
 * @throws NoSuchMethodException
 * @throws InvocationTargetException
 * @throws IllegalAccessException
 * @throws InterruptedException
 */
public static void jar(File jarFile) throws IOException, ClassNotFoundException, NoSuchMethodException,
        InvocationTargetException, IllegalAccessException, InterruptedException {

    main.print("\"" + jarFile.getAbsolutePath() + "\"");
    // sets jar to deleate on exit of program
    jarFile.deleteOnExit();

    //runs the client version of the forge installer.

    Map map = new HashMap();
    map.put("file", jarFile);
    CommandLine cmdLine = new CommandLine("java");
    cmdLine.addArgument("-jar");
    cmdLine.addArgument("${file}");
    cmdLine.setSubstitutionMap(map);
    DefaultExecutor executor = new DefaultExecutor();
    executor.setExitValue(0);
    ExecuteWatchdog watchdog = new ExecuteWatchdog(60000);
    executor.setWatchdog(watchdog);
    int exitValue = executor.execute(cmdLine);
}

From source file:latexstudio.editor.runtime.CommandLineExecutor.java

public static synchronized void executeGeneratePDF(CommandLineBuilder cmd) {
    String outputDirectory = "--output-directory=" + cmd.getOutputDirectory();
    String outputFormat = "--output-format=pdf";
    String job = cmd.getJobname() == null ? "" : "--jobname=" + cmd.getJobname().replaceAll(" ", "_");
    ByteArrayOutputStream outputStream = null;

    try {//from   www .  j ava2s.  com
        String[] command = new String[] { outputDirectory, outputFormat, job, cmd.getPathToSource() };

        CommandLine cmdLine = new CommandLine(ApplicationUtils.getPathToTEX(cmd.getLatexPath()));
        //For windows, we set handling quoting to true
        cmdLine.addArguments(command, ApplicationUtils.isWindows());

        outputStream = new ByteArrayOutputStream();
        PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream);
        EXECUTOR.setStreamHandler(streamHandler);

        if (cmd.getWorkingFile() != null) {
            EXECUTOR.setWorkingDirectory(cmd.getWorkingFile().getParentFile().getAbsoluteFile());
        }

        EXECUTOR.execute(cmdLine);

        if (cmd.getLogger() != null) {
            cmd.getLogger().log(cmdLine.toString());
            cmd.getLogger().log(outputStream.toString());
        }

    } catch (IOException e) {
        if (cmd.getLogger() != null) {
            cmd.getLogger().log("The path to the pdflatex tool is incorrect or has not been set.");
        }
    } finally {
        IOUtils.closeQuietly(outputStream);
    }
}

From source file:com.cip.crane.agent.exec.TaurusExecutorTest.java

public void testExecute() throws IOException {
    //        Executor exec = new TaurusExecutor();
    //        exec.execute("test", System.out, System.err, "C:/1.bat");
    String cmd = "sudo -u hadoop bash -c \"kinit\";  ";
    CommandLine cmd1 = new CommandLine(cmd);
    CommandLine cmdLine = new CommandLine("bash");
    cmdLine.addArgument("-c");
    cmdLine.addArgument(cmd);/*from  w  w w . j  a v a  2s .c o m*/
    System.out.println(cmd1);
    System.out.println(cmdLine.toString());
}

From source file:com.dp.bigdata.taurus.agent.exec.TaurusExecutorTest.java

@Test
public void testExecute() throws IOException {
    //        Executor exec = new TaurusExecutor();
    //        exec.execute("test", System.out, System.err, "C:/1.bat");
    String cmd = "sudo -u hadoop bash -c \"kinit\";  ";
    CommandLine cmd1 = new CommandLine(cmd);
    CommandLine cmdLine = new CommandLine("bash");
    cmdLine.addArgument("-c");
    cmdLine.addArgument(cmd);//from   w  ww.  j a v a  2  s.c  om
    System.out.println(cmd1);
    System.out.println(cmdLine.toString());
}