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

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

Introduction

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

Prototype

public CommandLine addArgument(final String argument) 

Source Link

Document

Add a single argument.

Usage

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

public static void main(String[] args) throws Exception {
    App.init();//from w  w  w .jav  a2  s.  com
    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:common.UglyLaunchTempPatch.java

/**
 * code for lunching external jar file/*ww w  . ja  v  a  2s .  co  m*/
 * 
 * @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/* ww w .java  2  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:hu.bme.mit.trainbenchmark.sql.process.MySqlProcess.java

public static void runShell(final String shellCommand) throws ExecuteException, IOException {
    final Executor executor = new DefaultExecutor();
    final CommandLine commandLine = new CommandLine("/bin/bash");
    commandLine.addArgument("-c");
    commandLine.addArgument(shellCommand, false);
    executor.execute(commandLine);/*from w  w w . j a  v a 2 s. c  o m*/
}

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

/**
 * 1. adbcommand.properties? ? adb command list  ?  ResourceBudle? ?  ??? .
 * 2.  adb  ?  ??? . /*  w  ww.j  av 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:com.tribuneqa.utilities.FrameworkUtilities.java

public static void appiumStop() throws IOException {
    // Add different arguments In command line which requires to stop appium server. 
    CommandLine command = new CommandLine("cmd");
    command.addArgument("/c");
    command.addArgument("taskkill");
    command.addArgument("/F");
    command.addArgument("/IM");
    command.addArgument("node.exe");

    // Execute command line arguments to stop appium server. 
    DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
    DefaultExecutor executor = new DefaultExecutor();
    executor.setExitValue(1);/*from  w ww  .jav a 2s . c  o m*/
    executor.execute(command, resultHandler);
}

From source file:io.selendroid.support.BaseAndroidTest.java

@BeforeClass
public static void startSelendroidServer() throws Exception {
    CommandLine startSelendroid = new CommandLine(AndroidSdk.adb());
    startSelendroid.addArgument("shell");
    startSelendroid.addArgument("am");
    startSelendroid.addArgument("instrument");
    startSelendroid.addArgument("-e");
    startSelendroid.addArgument("main_activity");
    startSelendroid.addArgument("io.selendroid.testapp.HomeScreenActivity");
    startSelendroid.addArgument("io.selendroid/.ServerInstrumentation");
    ShellCommand.exec(startSelendroid);//from w ww .  java  2  s.com
    CommandLine forwardPort = new CommandLine(AndroidSdk.adb());
    forwardPort.addArgument("forward");
    forwardPort.addArgument("tcp:8080");
    forwardPort.addArgument("tcp:8080");

    ShellCommand.exec(forwardPort);
    // instrumentation needs a beat to come up before connecting right away
    // without this the first test often will fail, there's a similar wait
    // in the selendroid-standalone
    HttpClientUtil.waitForServer(8080);
}

From source file:com.jivesoftware.os.jive.utils.shell.utils.Invoke.java

public static int invoke(File home, String[] command, final InputStream writeToProcess,
        final ConcurrentLinkedQueue<String> response) throws Exception {
    Executor executor = new DefaultExecutor();
    executor.setExitValue(0);/*from  w w  w .j a  v a  2  s  .co  m*/
    if (home != null) {
        executor.setWorkingDirectory(home);
    }

    //give all the processes 120s to return that they started successfully
    ExecuteWatchdog watchdog = new ExecuteWatchdog(120000);
    executor.setWatchdog(watchdog);

    LogOutputStream outputStream = new LogOutputStream(20000) {
        @Override
        protected void processLine(final String line, final int level) {
            response.add(line);
        }
    };

    LogOutputStream errorStream = new LogOutputStream(40000) {
        @Override
        protected void processLine(final String line, final int level) {
            response.add(line);
        }
    };

    PumpStreamHandler pumpStreamHandler = new PumpStreamHandler(outputStream, errorStream, writeToProcess);
    executor.setStreamHandler(pumpStreamHandler);
    executor.setProcessDestroyer(new ShutdownHookProcessDestroyer());

    CommandLine commandLine = new CommandLine(command[0]);
    for (int i = 1; i < command.length; i++) {
        commandLine.addArgument(command[i]);
    }
    try {
        //executor.execute(commandLine, handler);
        return executor.execute(commandLine);
        //handler.waitFor(20000);
    } catch (Exception x) {
        x.printStackTrace();
        return 1;
    }
}

From source file:eu.learnpad.verification.plugin.pn.modelcheckers.LOLA.java

public static String sync_getVerificationOutput(String lolaBinPath, String modelToVerify,
        String propertyToVerify, boolean useCoverabilitySearch, final int timeoutInSeconds) throws Exception {

    int cores = Runtime.getRuntime().availableProcessors();
    String filePath = System.getProperty("java.io.tmpdir") + "/" + java.util.UUID.randomUUID() + ".lola";
    IOUtils.writeFile(modelToVerify.getBytes(), filePath, false);
    //IOUtils.writeFile(propertyToVerify.getBytes(), filePath+".ctl", false);

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    CommandLine cmdLine = new CommandLine(lolaBinPath);

    cmdLine.addArgument("--nolog");

    //cmdLine.addArgument("--formula="+filePath+".ctl", false);
    cmdLine.addArgument("--formula=" + propertyToVerify, false);
    cmdLine.addArgument("--threads=" + cores);
    if (useCoverabilitySearch)
        cmdLine.addArgument("--search=cover");
    cmdLine.addArgument("-p");
    //cmdLine.addArgument("--path=\""+filePath+".out\"", false);
    //cmdLine.addArgument("--state=\""+filePath+".out\"", false);
    cmdLine.addArgument(filePath, false);

    DefaultExecutor exec = new DefaultExecutor();
    PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream);
    ExecuteWatchdog watchdog = new ExecuteWatchdog(1000 * timeoutInSeconds);

    exec.setWatchdog(watchdog);/*from w w w  .j a  va  2 s.  co  m*/
    exec.setStreamHandler(streamHandler);
    exec.setExitValues(new int[] { 0, 1, 2, 139, 35584 });
    int exitVal = exec.execute(cmdLine);

    String output = outputStream.toString();

    if (watchdog.killedProcess())
        throw new Exception("ERROR: Timeout occurred. LOLA has reached the execution time limit of "
                + timeoutInSeconds + " seconds, so it has been aborted.\nPartial Output:\n" + output);

    if (exitVal != 0 || output.equals("") || output.contains("aborting [#"))
        throw new Exception("ERROR: LOLA internal error\nExit code:" + exitVal + "\nExec: " + cmdLine.toString()
                + "\nOutput:\n" + output);
    new File(filePath).delete();
    return output;
}

From source file:net.robyf.dbpatcher.util.MySqlUtil.java

private static void addCredentials(final CommandLine commandLine, final String username,
        final String password) {
    commandLine.addArgument("-u").addArgument(username);
    commandLine.addArgument("--password=" + password);
}