当前位置: 首页>>代码示例>>Java>>正文


Java CommandLine.addArgument方法代码示例

本文整理汇总了Java中org.apache.commons.exec.CommandLine.addArgument方法的典型用法代码示例。如果您正苦于以下问题:Java CommandLine.addArgument方法的具体用法?Java CommandLine.addArgument怎么用?Java CommandLine.addArgument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.exec.CommandLine的用法示例。


在下文中一共展示了CommandLine.addArgument方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: runMavenCommand

import org.apache.commons.exec.CommandLine; //导入方法依赖的package包/类
@When("I run maven with args: (.*)")
public void runMavenCommand(List<String> mvnArgs) throws IOException {
    this.mvnArgs.addAll(mvnArgs);
    System.out.println("Launching Maven with args <" + Joiner.on(" ").join(mvnArgs) + ">");
    CommandLine cmdLine = new CommandLine(getCommandLine());
    for (String mvnArg : mvnArgs) {
        cmdLine.addArgument(mvnArg);
    }
    if (confdForCucumberLocation != null) {
        cmdLine.addArgument("-Dcucumber.confd.binary.path=" + confdForCucumberLocation);
    }
    DefaultExecutor executor = new DefaultExecutor();
    if (projectRootAsFile != null) {
        executor.setWorkingDirectory(projectRootAsFile);
    }
    executor.setExitValue(expectedExitCode);
    executor.setStreamHandler(new PumpStreamHandler(new LogOutputStream() {
        @Override
        protected void processLine(String line, int level) {
            System.out.println(line);
            executorOutput.add(line);
        }
    }));
    exitCode = executor.execute(cmdLine, environment);
    fullOutput = Joiner.on(LINE_SEPARATOR).join(executorOutput);
}
 
开发者ID:nodevops,项目名称:confd-maven-plugin,代码行数:27,代码来源:MavenRunnerStepdefs.java

示例2: buildActionCommand

import org.apache.commons.exec.CommandLine; //导入方法依赖的package包/类
private CommandLine buildActionCommand(String terraformPath, String action, Map<String, Object> variableMap) {

		CommandLine actionCommand = new CommandLine(terraformPath);
		actionCommand.addArgument(action);

		if (action.equals(Constants.ACTION_DESTROY)) {
			actionCommand.addArgument(FLAG_FORCE);
		}

		actionCommand.addArgument(FLAG_NO_COLOR);

		for (Entry<String, Object> variableEntry : variableMap.entrySet()) {

			String variableName = variableEntry.getKey();
			String variableValue = (String) variableEntry.getValue();
			String variableString = variableName + Constants.CHAR_EQUAL + (variableValue.equals("on") ? "true" : variableValue);

			actionCommand.addArgument(FLAG_VAR);
			actionCommand.addArgument(variableString, false);
		}

		return actionCommand;
	}
 
开发者ID:chrisipa,项目名称:cloud-portal,代码行数:24,代码来源:TerraformService.java

示例3: execToFile

import org.apache.commons.exec.CommandLine; //导入方法依赖的package包/类
/**
 * 日志文件输出方式
 *
 * 优点:支持将目标数据实时输出到指定日志文件中去
 * 缺点:
 *      标准输出和错误输出优先级固定,可能和脚本中顺序不一致
 *      Java无法实时获取
 *
 * @param command
 * @param scriptFile
 * @param logFile
 * @param params
 * @return
 * @throws IOException
 */
public static int execToFile(String command, String scriptFile, String logFile, String... params) throws IOException {
    // 标准输出:print (null if watchdog timeout)
    // 错误输出:logging + 异常 (still exists if watchdog timeout)
    // 标准输入
    FileOutputStream fileOutputStream = new FileOutputStream(logFile, true);
    PumpStreamHandler streamHandler = new PumpStreamHandler(fileOutputStream, fileOutputStream, null);

    // command
    CommandLine commandline = new CommandLine(command);
    commandline.addArgument(scriptFile);
    if (params!=null && params.length>0) {
        commandline.addArguments(params);
    }

    // exec
    DefaultExecutor exec = new DefaultExecutor();
    exec.setExitValues(null);
    exec.setStreamHandler(streamHandler);
    int exitValue = exec.execute(commandline);  // exit code: 0=success, 1=error
    return exitValue;
}
 
开发者ID:mmwhd,项目名称:stage-job,代码行数:37,代码来源:ScriptUtil.java

示例4: 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

示例5: compile

import org.apache.commons.exec.CommandLine; //导入方法依赖的package包/类
public void compile(String cwd, Submission submission) throws RuntimeException {
    ByteArrayOutputStream stderr = new ByteArrayOutputStream();
    ExecuteWatchdog watchdog = new ExecuteWatchdog(watchdogTimeout);

    DefaultExecutor executor = new DefaultExecutor();
    executor.setWorkingDirectory(new File(cwd));
    executor.setStreamHandler(new PumpStreamHandler(null, stderr, null));
    executor.setWatchdog(watchdog);

    CommandLine cmd = new CommandLine(javac);
    cmd.addArgument("-J-Duser.language=en");  // force using English
    cmd.addArgument("-classpath");
    cmd.addArgument(cwd);
    cmd.addArgument(fileName + ".java");
    logger.info("Compiler cmd:\t" + cmd.toString());

    try {
        executor.execute(cmd);
        logger.info("Compile OK");
    } catch (IOException e) {
        if (watchdog.killedProcess()) {
            submission.setStatus(Submission.STATUS_CE);
            submission.setError("Compile Time Exceeded");
            logger.warn("Compile Time Exceeded:\t" + e.getMessage());
        } else {
            submission.setStatus(Submission.STATUS_CE);
            submission.setError("Compile error");
            logger.warn("Compile error:\t" + e.getMessage());
        }
        logger.warn(stderr.toString());
        throw new RuntimeException("Compile Aborted.");
    }
}
 
开发者ID:justice-oj,项目名称:dispatcher,代码行数:34,代码来源:JavaWorker.java

示例6: compile

import org.apache.commons.exec.CommandLine; //导入方法依赖的package包/类
public void compile(String cwd, Submission submission) throws RuntimeException {
    CommandLine cmd = new CommandLine(compiler);
    cmd.addArgument("-basedir=" + cwd);
    cmd.addArgument("-compiler=" + realCompiler);
    cmd.addArgument("-filename=" + fileName + "." + suffix);
    cmd.addArgument("-timeout=" + watchdogTimeout);
    cmd.addArgument("-std=" + std);
    logger.info(cmd.toString());

    ByteArrayOutputStream stderr = new ByteArrayOutputStream();
    DefaultExecutor executor = new DefaultExecutor();
    executor.setStreamHandler(new PumpStreamHandler(null, stderr, null));
    try {
        executor.execute(cmd);
        if (stderr.toString().length() > 0) {
            submission.setStatus(Submission.STATUS_CE);
            submission.setError("Compile error");
            logger.warn(stderr.toString());
            throw new RuntimeException("Sandbox Aborted.");
        }
        logger.info("Compile OK");
    } catch (IOException e) {
        logger.warn("Compile error:\t" + e.getMessage());
        throw new RuntimeException("An Error Occurred.");
    }
}
 
开发者ID:justice-oj,项目名称:dispatcher,代码行数:27,代码来源:CLikeWorker.java

示例7: exec

import org.apache.commons.exec.CommandLine; //导入方法依赖的package包/类
/**
 * Esegue un comando di shell
 * @param command comando
 * @param args lista di argomenti (ogni elemento puo' contenere spazi), puo' essere null
 * @param outputStream ByteArrayOutputStream che conterrà l'output del comando
 * @return the error message (will be empty for a return code >0), or null if there was no error
 */
public String exec(String command, List<String> args, ByteArrayOutputStream outputStream) {
	int exitValue=1;
	try {
		CommandLine commandLine = new CommandLine(command);
		if (args!=null) {
			for (String arg : args) {
				commandLine.addArgument(arg, false); // Don't handle quoting
			}
		}
		DefaultExecutor executor = new DefaultExecutor();
		PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream);
		executor.setStreamHandler(streamHandler);
		log.debug("Executing shell command: {}", commandLine);
		exitValue = executor.execute(commandLine);
	} catch (Exception e) {
		log.error("Failed to execute shell command: " + command + " " + args, e);
		return e.getMessage();
	}
	return exitValue>0?"":null;
}
 
开发者ID:xtianus,项目名称:yadaframework,代码行数:28,代码来源:YadaUtil.java

示例8: handle

import org.apache.commons.exec.CommandLine; //导入方法依赖的package包/类
@Override
public Map<String,Object> handle (Task aTask) throws Exception {
  CommandLine cmd = new CommandLine ("mediainfo");
  cmd.addArgument(aTask.getRequiredString("input"));
  log.debug("{}",cmd);
  DefaultExecutor exec = new DefaultExecutor();
  File tempFile = File.createTempFile("log", null);
  try (PrintStream stream = new PrintStream(tempFile);) {
    exec.setStreamHandler(new PumpStreamHandler(stream));
    exec.execute(cmd);
    return parse(FileUtils.readFileToString(tempFile));
  }
  catch (ExecuteException e) {
    throw new ExecuteException(e.getMessage(),e.getExitValue(), new RuntimeException(FileUtils.readFileToString(tempFile)));
  }
  finally {
    FileUtils.deleteQuietly(tempFile);
  }
}
 
开发者ID:creactiviti,项目名称:piper,代码行数:20,代码来源:Mediainfo.java

示例9: runCancelJob

import org.apache.commons.exec.CommandLine; //导入方法依赖的package包/类
private void runCancelJob(Master.Job message) {
    if (getAbortStatus(message.abortUrl, message.trackingId)) {
        CommandLine cmdLine = new CommandLine("/bin/bash");
        cmdLine.addArgument(agentConfig.getJob().getJobArtifact("cancel"));
        cmdLine.addArgument(message.jobId);
        DefaultExecutor killExecutor = new DefaultExecutor();
        ExecuteWatchdog watchdog = new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT);
        killExecutor.setWatchdog(watchdog);
        try {
            log.info("Cancel command: {}", cmdLine);
            killExecutor.execute(cmdLine);
            TaskEvent taskEvent = (TaskEvent) message.taskEvent;
            String outPath = agentConfig.getJob().getOutPath(taskEvent.getJobName(), message.jobId);
            String errPath = agentConfig.getJob().getErrorPath(taskEvent.getJobName(), message.jobId);
            Worker.Result result = new Worker.Result(-9, agentConfig.getUrl(errPath), agentConfig.getUrl(outPath), null, message);
            getSender().tell(new Worker.WorkFailed(result), getSelf());
        } catch (IOException e) {
            log.error(e, "Error cancelling job");
        }
    }
}
 
开发者ID:Abiy,项目名称:distGatling,代码行数:22,代码来源:JarExecutor.java

示例10: getJarCommand

import org.apache.commons.exec.CommandLine; //导入方法依赖的package包/类
private CommandLine getJarCommand(Master.Job job, TaskEvent taskEvent) {
    CommandLine cmdLine = new CommandLine("java");
    cmdLine.addArgument("-jar");

    //download the data feed
    if(taskEvent.getJobInfo().hasDataFeed) {
        log.info("Downloading from {}  to {}", job.dataFileUrl,agentConfig.getJob().getJobDirectory(job.jobId, DATA,taskEvent.getJobInfo().dataFileName));
        DownloadFile.downloadFile(job.dataFileUrl, agentConfig.getJob().getJobDirectory(job.jobId, DATA,taskEvent.getJobInfo().dataFileName));
        //job data feed  path
    }
    cmdLine.addArgument("-DdataFolder=" + agentConfig.getJob().getJobDirectory(job.jobId,DATA));
    cmdLine.addArgument("-DresultsFolder=" + agentConfig.getJob().getResultPath(job.roleId, job.jobId));
    cmdLine.addArgument("-DnoReports=true");
    //parameters come from the task event
    for (String pair : taskEvent.getParameters()) {
        cmdLine.addArgument(pair);
    }
    log.info("Downloading jar to {} ",agentConfig.getJob().getJobDirectory(job.jobId, SIMULATION, taskEvent.getJobInfo().jarFileName));
    //download the simulation or jar file
    DownloadFile.downloadFile(job.jobFileUrl,agentConfig.getJob().getJobDirectory(job.jobId, SIMULATION, taskEvent.getJobInfo().jarFileName));//.jar

    cmdLine.addArgument(agentConfig.getJob().getJobDirectory(job.jobId, SIMULATION, taskEvent.getJobInfo().jarFileName));//.jar
    return cmdLine;
}
 
开发者ID:Abiy,项目名称:distGatling,代码行数:25,代码来源:JarExecutor.java

示例11: runCancelJob

import org.apache.commons.exec.CommandLine; //导入方法依赖的package包/类
private void runCancelJob(Master.Job message) {
    if (getAbortStatus(message.abortUrl, message.trackingId)) {
        CommandLine cmdLine = new CommandLine("/bin/bash");
        cmdLine.addArgument(agentConfig.getJob().getJobArtifact("cancel"));
        cmdLine.addArgument(message.jobId);
        DefaultExecutor killExecutor = new DefaultExecutor();
        ExecuteWatchdog watchdog = new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT);
        killExecutor.setWatchdog(watchdog);
        try {
            log.info("Cancel command: {}", cmdLine);
            killExecutor.execute(cmdLine);
        } catch (IOException e) {
            log.error(e, "Error cancelling job");
        }
    }
}
 
开发者ID:Abiy,项目名称:distGatling,代码行数:17,代码来源:ScriptExecutor.java

示例12: recordMerge

import org.apache.commons.exec.CommandLine; //导入方法依赖的package包/类
/**
 * Record a manual merge from one branch to the local working directory.
 *
 * @param directory The local working directory
 * @param branchName The branch that was merged in manually
 * @param revisions The list of merged revisions.
 * @return A stream which provides the output of the "svn merge" command, should be closed by the caller
 * @throws IOException Execution of the SVN sub-process failed or the
 *          sub-process returned a exit value indicating a failure
 */
public static InputStream recordMerge(File directory, String branchName, long... revisions) throws IOException {
    // 				svn merge -c 3328 --record-only ^/calc/trunk
    CommandLine cmdLine = new CommandLine(SVN_CMD);
    cmdLine.addArgument(CMD_MERGE);
    addDefaultArguments(cmdLine, null, null);
    cmdLine.addArgument("--record-only");
    cmdLine.addArgument("-c");
    StringBuilder revs = new StringBuilder();
    for (long revision : revisions) {
        revs.append(revision).append(",");
    }
    cmdLine.addArgument(revs.toString());
    // leads to "non-inheritable merges"
    // cmdLine.addArgument("--depth");
    // cmdLine.addArgument("empty");
    cmdLine.addArgument("^" + branchName);
    //cmdLine.addArgument(".");	// current dir

    return ExecutionHelper.getCommandResult(cmdLine, directory, 0, 120000);
}
 
开发者ID:centic9,项目名称:commons-dost,代码行数:31,代码来源:SVNCommands.java

示例13: checkDot

import org.apache.commons.exec.CommandLine; //导入方法依赖的package包/类
/**
 * Verify if dot can be started and print out the version to stdout.
 *
 * @return True if "dot -V" ran successfully, false otherwise
 *
 * @throws IOException If running dot fails.
 */
public static boolean checkDot() throws IOException {
	// call graphviz-dot via commons-exec
	CommandLine cmdLine = new CommandLine(DOT_EXE);
	cmdLine.addArgument("-V");
	DefaultExecutor executor = new DefaultExecutor();
	executor.setExitValue(0);
	ExecuteWatchdog watchdog = new ExecuteWatchdog(60000);
	executor.setWatchdog(watchdog);
	executor.setStreamHandler(new PumpStreamHandler(System.out, System.err));
	int exitValue = executor.execute(cmdLine);
	if(exitValue != 0) {
		System.err.println("Could not run '" + DOT_EXE + "', had exit value: " + exitValue + "!");
		return false;
	}

	return true;
}
 
开发者ID:centic9,项目名称:commons-dost,代码行数:25,代码来源:DotUtils.java

示例14: getVersion

import org.apache.commons.exec.CommandLine; //导入方法依赖的package包/类
public int getVersion() throws Exception {
	ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
	CommandLine cmdLine = new CommandLine(p4d);
	cmdLine.addArgument("-V");
	DefaultExecutor executor = new DefaultExecutor();
	PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream);
	executor.setStreamHandler(streamHandler);
	executor.execute(cmdLine);

	int version = 0;
	for (String line : outputStream.toString().split("\\n")) {
		if (line.startsWith("Rev. P4D")) {
			Pattern p = Pattern.compile("\\d{4}\\.\\d{1}");
			Matcher m = p.matcher(line);
			while (m.find()) {
				String found = m.group();
				found = found.replace(".", ""); // strip "."
				version = Integer.parseInt(found);
			}
		}
	}
	logger.info("P4D Version: " + version);
	return version;
}
 
开发者ID:p4paul,项目名称:p4workflow,代码行数:25,代码来源:P4Server.java

示例15: buildInitCommand

import org.apache.commons.exec.CommandLine; //导入方法依赖的package包/类
private CommandLine buildInitCommand(String terraformPath) {

		CommandLine initCommand = new CommandLine(terraformPath);
		initCommand.addArgument(Constants.ACTION_INIT);
		initCommand.addArgument(FLAG_NO_COLOR);

		return initCommand;
	}
 
开发者ID:chrisipa,项目名称:cloud-portal,代码行数:9,代码来源:TerraformService.java


注:本文中的org.apache.commons.exec.CommandLine.addArgument方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。