当前位置: 首页>>代码示例>>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;未经允许,请勿转载。