當前位置: 首頁>>代碼示例>>Java>>正文


Java CommandLine.parse方法代碼示例

本文整理匯總了Java中org.apache.commons.exec.CommandLine.parse方法的典型用法代碼示例。如果您正苦於以下問題:Java CommandLine.parse方法的具體用法?Java CommandLine.parse怎麽用?Java CommandLine.parse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.exec.CommandLine的用法示例。


在下文中一共展示了CommandLine.parse方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testExecutable

import org.apache.commons.exec.CommandLine; //導入方法依賴的package包/類
private static boolean testExecutable() {
    CommandLine commandLine = CommandLine.parse(RCLIProcessor.rExecutable + " " + VERSION_CALL);

    DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
    Executor executor = new DefaultExecutor();

    // put a watchdog with a timeout
    ExecuteWatchdog watchdog = new ExecuteWatchdog(new Long(TIMEOUT_SECONDS) * 1000);
    executor.setWatchdog(watchdog);

    try {
        executor.execute(commandLine, resultHandler);
        resultHandler.waitFor();
        int exitVal = resultHandler.getExitValue();
        if (exitVal != 0) {
            return false;
        }
            return true;
    }
    catch (Exception e) {
        return false;
    }
}
 
開發者ID:52North,項目名稱:movingcode,代碼行數:24,代碼來源:RCLIProbe.java

示例2: testExecutable

import org.apache.commons.exec.CommandLine; //導入方法依賴的package包/類
public static boolean testExecutable() {
	CommandLine commandLine = CommandLine.parse(PythonCLIProcessor.pythonExecutable + " --version");

	DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
	Executor executor = new DefaultExecutor();

	// put a watchdog with a timeout
	ExecuteWatchdog watchdog = new ExecuteWatchdog(new Long(timeout_seconds) * 1000);
	executor.setWatchdog(watchdog);

	try {
		executor.execute(commandLine, resultHandler);
		resultHandler.waitFor();
		int exitVal = resultHandler.getExitValue();
		if (exitVal != 0) {
			return false;
		}
		return true;
	}
	catch (Exception e) {
		return false;
	}
}
 
開發者ID:52North,項目名稱:movingcode,代碼行數:24,代碼來源:PythonCLIProbe.java

示例3: startJekyllCI

import org.apache.commons.exec.CommandLine; //導入方法依賴的package包/類
/**
 * Starts the jekyll build process (jekyll build --incremental)
 * @return true, if jekyll build was successful
 */
public boolean startJekyllCI() {
	int exitValue = -1;
	String line = JEKYLL_PATH;
	ByteArrayOutputStream jekyllBuildOutput = new ByteArrayOutputStream();
	CommandLine cmdLine = CommandLine.parse(line);
	cmdLine.addArgument(JEKYLL_OPTION_BUILD);
	cmdLine.addArgument(JEKYLL_OPTION_INCR);
	DefaultExecutor executor = new DefaultExecutor();
	executor.setWorkingDirectory(new File(LOCAL_REPO_PATH));
	PumpStreamHandler streamHandler = new PumpStreamHandler(jekyllBuildOutput);
	executor.setStreamHandler(streamHandler);
	try {
		LOGGER.info("Starting jekyll build");
		exitValue = executor.execute(cmdLine);
		LOGGER.info("Jekyll build command executed");
	} catch (IOException e) {
		LOGGER.error("Error while executing jekyll build. Error message: {}", e.getMessage());
		e.printStackTrace();
		return false;
	}
	printJekyllStatus(exitValue, jekyllBuildOutput.toString());
	return true;
}
 
開發者ID:adessoAG,項目名稱:jekyll2cms,代碼行數:28,代碼來源:JekyllService.java

示例4: main

import org.apache.commons.exec.CommandLine; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    String cmd = "/tmp/test.sh";
    CommandLine cmdLine = CommandLine.parse("/bin/bash " + cmd);

    ByteArrayOutputStream stdout = new ByteArrayOutputStream();
    ByteArrayOutputStream stderr = new ByteArrayOutputStream();
    PumpStreamHandler psh = new PumpStreamHandler(stdout, stderr);

    psh.setStopTimeout(TIMEOUT_FIVE_MINUTES);

    ExecuteWatchdog watchdog = new ExecuteWatchdog(TIMEOUT_TEN_MINUTES); // timeout in milliseconds

    Executor executor = new DefaultExecutor();
    executor.setExitValue(0);
    executor.setStreamHandler(psh);
    executor.setWatchdog(watchdog);

    int exitValue = executor.execute(cmdLine, Collections.emptyMap());
    System.out.println(exitValue);
}
 
開發者ID:kinow,項目名稱:commons-sandbox,代碼行數:21,代碼來源:Tests.java

示例5: testCommonsCodecsConflicts

import org.apache.commons.exec.CommandLine; //導入方法依賴的package包/類
@Test
public void testCommonsCodecsConflicts() throws IOException, VerificationException {
    SetupContent setupContent = new SetupContent().invoke();
    String shadedJar = setupContent.getShadedJar();
    String issue24POM = setupContent.getIssue24POM();
    String issue24TestFile = setupContent.getIssue24TestFile();
    File cwdFile = setupContent.getCwdFile();
    

    String line = String.format("java -jar %s -v -p %s %s %s", shadedJar, issue24POM, issue24TestFile,
            StringUtils.join(new String[] {cwdFile.getAbsolutePath(), "testCommonsCodecsConflicts.html"}, File.separator));
    CommandLine command = CommandLine.parse(line);
    DefaultExecutor executor = new DefaultExecutor();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ByteArrayOutputStream err = new ByteArrayOutputStream();
    executor.setStreamHandler(new PumpStreamHandler(out, err));
    executor.execute(command);
}
 
開發者ID:strator-dev,項目名稱:greenpepper,代碼行數:19,代碼來源:ShadingTest.java

示例6: shouldNotOverwriteInputFile

import org.apache.commons.exec.CommandLine; //導入方法依賴的package包/類
@Test
public void shouldNotOverwriteInputFile() throws IOException, VerificationException {
    SetupContent setupContent = new SetupContent().invoke();
    String shadedJar = setupContent.getShadedJar();
    String issue24POM = setupContent.getIssue24POM();
    String issue24TestFile = setupContent.getIssue24TestFile();
    File specFile = new File(issue24TestFile);
    File specBackupFile = new File(issue24TestFile + ".orig");
    FileUtils.copyFile(specFile, specBackupFile);

    String line = String.format("java -jar %s -v -p %s %s", shadedJar, issue24POM, issue24TestFile);
    CommandLine command = CommandLine.parse(line);
    DefaultExecutor executor = new DefaultExecutor();
    executor.setWorkingDirectory(specFile.getParentFile());
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ByteArrayOutputStream err = new ByteArrayOutputStream();
    executor.setStreamHandler(new PumpStreamHandler(out, err));
    executor.execute(command);

    assertTrue("The specification should not be overriden by the output", FileUtils.contentEquals(specFile,specBackupFile));
}
 
開發者ID:strator-dev,項目名稱:greenpepper,代碼行數:22,代碼來源:ShadingTest.java

示例7: testRunEchoHelloWorld

import org.apache.commons.exec.CommandLine; //導入方法依賴的package包/類
@Test
void testRunEchoHelloWorld() throws IOException, InterruptedException {
    final CommandLine expected = SystemUtils.IS_OS_WINDOWS
            ? CommandLine.parse("cmd /C echo hello world")
            : CommandLine.parse("/bin/sh -c").addArgument("echo hello world", false);

    final DefaultExecutor cmdExecMock = Mockito.mock(DefaultExecutor.class);
    final CommandRunner cmdRunner = new CommandBuilder()
            .withShellWrapper(true)
            .withCommandExecutor(cmdExecMock)
            .build();

    cmdRunner.exec(CommandLine.parse("echo hello world"), null);

    verify(cmdExecMock).execute(runEchoCaptor.capture(), (File) isNull());
    assertEquals(expected.toString(), runEchoCaptor.getValue().toString());
}
 
開發者ID:nidi3,項目名稱:graphviz-java,代碼行數:18,代碼來源:CommandRunnerTest.java

示例8: createSecureConfiguration

import org.apache.commons.exec.CommandLine; //導入方法依賴的package包/類
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("zeppelin.shell.keytab.location"),
      properties.getProperty("zeppelin.shell.principal"));
  cmdLine.addArgument(kinitCommand, false);
  DefaultExecutor executor = new DefaultExecutor();
  try {
    executor.execute(cmdLine);
  } catch (Exception e) {
    LOGGER.error("Unable to run kinit for zeppelin user " + kinitCommand, e);
    throw new InterpreterException(e);
  }
}
 
開發者ID:apache,項目名稱:zeppelin,代碼行數:17,代碼來源:ShellInterpreter.java

示例9: run

import org.apache.commons.exec.CommandLine; //導入方法依賴的package包/類
public static int run(final GeneratorConfig gc, final ExecutionConfig ec) throws IOException, InterruptedException {
	final File configFile = File.createTempFile("trainbenchmark-generator-", ".conf");
	final String configPath = configFile.getAbsolutePath();
	gc.saveToFile(configPath);

	final String projectName = String.format("trainbenchmark-generator-%s", gc.getProjectName());
	final String jarPath = String.format("../%s/build/libs/%s-1.0.0-SNAPSHOT-fat.jar", projectName, projectName);
	final String javaCommand = String.format("java -Xms%s -Xmx%s -server -jar %s %s", ec.getXms(), ec.getXmx(),
			jarPath, configPath);

	final CommandLine cmdLine = CommandLine.parse(javaCommand);
	final DefaultExecutor executor = new DefaultExecutor();
	try {
		final int exitValue = executor.execute(cmdLine);
		System.out.println();
		return exitValue;
	} catch (final ExecuteException e) {
		e.printStackTrace(System.out);
		return e.getExitValue();
	}
}
 
開發者ID:FTSRG,項目名稱:trainbenchmark,代碼行數:22,代碼來源:GeneratorRunner.java

示例10: executeCommand

import org.apache.commons.exec.CommandLine; //導入方法依賴的package包/類
public static int executeCommand(String command,ExecuteWatchdog watchdog) {
	CommandLine cmdLine = CommandLine.parse(command);
	DefaultExecutor executor = new DefaultExecutor();
	executor.setStreamHandler(new PumpStreamHandler(System.out,System.err, null));
	executor.setExitValues(new int[]{0, 1});
	if(watchdog != null){
		executor.setWatchdog(watchdog);
	}
	int exitValue = 0;
	try {
		exitValue = executor.execute(cmdLine);
	} catch (IOException e) {
		exitValue = 1;
		log.error("error executing command", e);
	}
	return exitValue;
}
 
開發者ID:mohitsoni,項目名稱:compose-executor,代碼行數:18,代碼來源:ProcessUtils.java

示例11: buildCommand

import org.apache.commons.exec.CommandLine; //導入方法依賴的package包/類
private Protos.CommandInfo buildCommand(final Protos.CommandInfo.URI uri, final String script, final ShardingContexts shardingContexts, final boolean isCommandExecutor) {
    Protos.CommandInfo.Builder result = Protos.CommandInfo.newBuilder().addUris(uri).setShell(true);
    if (isCommandExecutor) {
        CommandLine commandLine = CommandLine.parse(script);
        commandLine.addArgument(GsonFactory.getGson().toJson(shardingContexts), false);
        result.setValue(Joiner.on(" ").join(commandLine.getExecutable(), Joiner.on(" ").join(commandLine.getArguments())));
    } else {
        result.setValue(script);
    }
    return result.build();
}
 
開發者ID:elasticjob,項目名稱:elastic-job-cloud,代碼行數:12,代碼來源:TaskLaunchScheduledService.java

示例12: executeScript

import org.apache.commons.exec.CommandLine; //導入方法依賴的package包/類
private void executeScript(final ShardingContext shardingContext, final String scriptCommandLine) {
    CommandLine commandLine = CommandLine.parse(scriptCommandLine);
    commandLine.addArgument(GsonFactory.getGson().toJson(shardingContext), false);
    try {
        new DefaultExecutor().execute(commandLine);
    } catch (final IOException ex) {
        throw new JobConfigurationException("Execute script failure.", ex);
    }
}
 
開發者ID:elasticjob,項目名稱:elastic-job-cloud,代碼行數:10,代碼來源:ScriptJobExecutor.java

示例13: execToString

import org.apache.commons.exec.CommandLine; //導入方法依賴的package包/類
public String execToString(String command) throws Exception {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    CommandLine commandline = CommandLine.parse(command);
    DefaultExecutor exec = new DefaultExecutor();
    PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream);
    exec.setStreamHandler(streamHandler);
    exec.execute(commandline);
    return (outputStream.toString());
}
 
開發者ID:MohamadSaada,項目名稱:LogiGSK,代碼行數:10,代碼來源:LogiGSKService.java

示例14: menuItem1ActionPerformed

import org.apache.commons.exec.CommandLine; //導入方法依賴的package包/類
private void menuItem1ActionPerformed(ActionEvent e) {
    if(this.api == ModificationAPI.BUKKIT) {
        showBukkitIncompatibleFeature();
        return;
    }
    System.out.println("Starting client...");
    SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
        @Override
        protected Void doInBackground() throws Exception {
            GradleConnector.newConnector().forProjectDirectory(workDirectory).connect().newBuild().forTasks("runClient").run();
            return null;
        }
    };
    if(this.api == ModificationAPI.MCP) {
        worker = new SwingWorker<Void, Void>() {
            @Override
            protected Void doInBackground() throws Exception {
                if(System.getProperty("os.name").startsWith("Windows")) {
                    Runtime.getRuntime().exec("cmd /c startclient.bat", null, workDirectory);
                    return null;
                }
                try {
                    CommandLine startClient = CommandLine.parse("python " + new File(new File(workDirectory, "runtime"), "startclient.py").getAbsolutePath() + " [email protected]");
                    CommandLine authClient = CommandLine.parse("chmod 755 " + new File(new File(workDirectory, "runtime"), "startclient.py").getAbsolutePath());
                    DefaultExecutor executor = new DefaultExecutor();
                    executor.setWorkingDirectory(workDirectory);
                    executor.execute(authClient);
                    executor.execute(startClient);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return null;
            }
        };
    }
    worker.execute();
}
 
開發者ID:TorchPowered,項目名稱:OpenByte,代碼行數:38,代碼來源:WorkFrame.java

示例15: menuItem2ActionPerformed

import org.apache.commons.exec.CommandLine; //導入方法依賴的package包/類
private void menuItem2ActionPerformed(ActionEvent e) {
    if(this.api == ModificationAPI.BUKKIT) {
        showBukkitIncompatibleFeature();
        return;
    }
    System.out.println("Starting server...");
    SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
        @Override
        protected Void doInBackground() throws Exception {
            GradleConnector.newConnector().forProjectDirectory(workDirectory).connect().newBuild().forTasks("runServer").run();
            return null;
        }
    };
    if (this.api == ModificationAPI.MCP) {
        worker = new SwingWorker<Void, Void>() {
            @Override
            protected Void doInBackground() throws Exception {
                if (System.getProperty("os.name").startsWith("Windows")) {
                    Runtime.getRuntime().exec("cmd /c startserver.bat", null, workDirectory);
                    return null;
                }
                try {
                    CommandLine startServer = CommandLine.parse("python " + new File(new File(workDirectory, "runtime"), "startserver.py").getAbsolutePath() + " [email protected]");
                    CommandLine authServer = CommandLine.parse("chmod 755 " + new File(new File(workDirectory, "runtime"), "startserver.py").getAbsolutePath());
                    DefaultExecutor executor = new DefaultExecutor();
                    executor.setWorkingDirectory(workDirectory);
                    executor.execute(authServer);
                    executor.execute(startServer);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return null;
            }
        };
    }
    worker.execute();
}
 
開發者ID:TorchPowered,項目名稱:OpenByte,代碼行數:38,代碼來源:WorkFrame.java


注:本文中的org.apache.commons.exec.CommandLine.parse方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。