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


Java CommandLine.addArguments方法代码示例

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


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

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

示例2: execute

import org.apache.commons.exec.CommandLine; //导入方法依赖的package包/类
public int execute(String[] args, @Nullable Path workingDir, Map<String, String> addEnv) throws IOException {
  if (!Files.isExecutable(file)) {
    Set<PosixFilePermission> perms = new HashSet<PosixFilePermission>();
    perms.add(PosixFilePermission.OWNER_READ);
    perms.add(PosixFilePermission.OWNER_EXECUTE);
    Files.setPosixFilePermissions(file, perms);
  }

  ExecuteWatchdog watchdog = new ExecuteWatchdog(TIMEOUT);
  CommandLine cmd = new CommandLine(file.toFile());
  cmd.addArguments(args);
  DefaultExecutor exec = new DefaultExecutor();
  exec.setWatchdog(watchdog);
  exec.setStreamHandler(createStreamHandler());
  exec.setExitValues(null);
  if (workingDir != null) {
    exec.setWorkingDirectory(workingDir.toFile());
  }
  in.close();
  LOG.info("Executing: {}", cmd.toString());
  Map<String, String> env = new HashMap<>(System.getenv());
  env.putAll(addEnv);
  return exec.execute(cmd, env);
}
 
开发者ID:SonarSource,项目名称:sonarlint-cli,代码行数:25,代码来源:CommandExecutor.java

示例3: toEngineCommand

import org.apache.commons.exec.CommandLine; //导入方法依赖的package包/类
private CommandLine toEngineCommand(Command command)
{
  String classpath = context.engineClasspathJarPath;
  if (StringUtils.isNotBlank(context.vmOptions.additionalClasspath))
  {
    classpath += File.pathSeparator + context.vmOptions.additionalClasspath;
  }
  
  File osgiDir = new File(context.engineDirectory, OsgiDir.INSTALL_AREA);
  
  CommandLine cli = new CommandLine(new File(getJavaExec()))
          .addArgument("-classpath").addArgument(classpath)
          .addArgument("-Divy.engine.testheadless=true")
          .addArgument("-Dosgi.install.area=" + osgiDir.getAbsolutePath());
  		
  if (StringUtils.isNotBlank(context.vmOptions.additionalVmOptions))
  {
    cli.addArguments(context.vmOptions.additionalVmOptions, false);
  }
  cli.addArgument("org.eclipse.equinox.launcher.Main")
          .addArgument("-application").addArgument("ch.ivyteam.ivy.server.exec.engine")
          .addArgument(command.toString());
  return cli;
}
 
开发者ID:axonivy,项目名称:project-build-plugin,代码行数:25,代码来源:EngineControl.java

示例4: newNodetoolCommandLine

import org.apache.commons.exec.CommandLine; //导入方法依赖的package包/类
/**
 * Creates the command line to launch the {@code nodetool} utility.
 *
 * @param args the command line arguments to pass to the {@code nodetool} utility.
 * @return the {@link CommandLine} to launch {@code nodetool} with the supplied arguments.
 * @throws IOException if there are issues creating the cassandra home directory.
 */
protected CommandLine newNodetoolCommandLine( String... args )
    throws IOException
{
    createCassandraHome();
    CommandLine commandLine = newJavaCommandLine();
    commandLine.addArgument( "-jar" );
    // It seems that java cannot handle quoted jar file names...
    commandLine.addArgument( new File( new File( cassandraDir, "bin" ), "nodetool.jar" ).getAbsolutePath(), false );
    commandLine.addArgument( "--host" );
    commandLine.addArgument( "127.0.0.1" );
    commandLine.addArgument( "--port" );
    commandLine.addArgument( Integer.toString( jmxPort ) );
    commandLine.addArguments( args );
    return commandLine;
}
 
开发者ID:mojohaus,项目名称:cassandra-maven-plugin,代码行数:23,代码来源:AbstractCassandraMojo.java

示例5: doTaskAction

import org.apache.commons.exec.CommandLine; //导入方法依赖的package包/类
@TaskAction
public void doTaskAction() {
    if (schemeName == null) {
        logger.info("Unit test scheme is not defined. Skipping unit test execution.");
    } else {
        CommandLine commandLine = new CommandLine("xcodebuild");
        commandLine.addArguments(new String[] {"-scheme", schemeName, "-sdk", "iphonesimulator", "clean", "test"}, false);
        ExecResult execResult = ExecUtil.execCommand(commandLine, null, null, true, true);
        for (String line : execResult.getOutput()) {
            if (line.contains("** TEST FAILED **")) {
                ErrorUtil.errorInTask(this.getName(), "Test errors detected, please review logs for details");
            }
        }
    }
}
 
开发者ID:ctco,项目名称:gradle-mobile-plugin,代码行数:16,代码来源:UnitTestingTask.java

示例6: getCheckedoutCommitTimestamp

import org.apache.commons.exec.CommandLine; //导入方法依赖的package包/类
public static long getCheckedoutCommitTimestamp(File dir) {
    CommandLine commandLine = new CommandLine("git");
    commandLine.addArguments(new String[] {"log", "-n", "1", "--pretty=format:%ct"}, false);
    ExecResult execResult = ExecUtil.execCommand(commandLine, dir, null, true, false);
    if (execResult.isSuccess()) {
        return Long.parseLong(execResult.getOutput().get(0));
    } else {
        return 0L;
    }
}
 
开发者ID:ctco,项目名称:gradle-mobile-plugin,代码行数:11,代码来源:GitUtil.java

示例7: validatePlist

import org.apache.commons.exec.CommandLine; //导入方法依赖的package包/类
public static void validatePlist(File plistFile) throws IOException {
    CommandLine commandLine = new CommandLine("plutil");
    commandLine.addArguments(new String[]{"-lint", "-s", plistFile.getAbsolutePath()}, false);
    ExecResult execResult = ExecUtil.execCommand(commandLine, null, null, false, false);
    if (!execResult.isSuccess()) {
        throw new IOException(execResult.getException());
    }
}
 
开发者ID:ctco,项目名称:gradle-mobile-plugin,代码行数:9,代码来源:PlistUtil.java

示例8: convertProvisioningToPlist

import org.apache.commons.exec.CommandLine; //导入方法依赖的package包/类
private static void convertProvisioningToPlist(File profile, File plist) throws IOException {
    CommandLine commandLine = new CommandLine("security");
    commandLine.addArguments(new String[] {"cms", "-D", "-i", profile.getAbsolutePath(), "-o", plist.getAbsolutePath()}, false);
    ExecResult execResult = ExecUtil.execCommand(commandLine, null, null, false, false);
    if (!execResult.isSuccess()) {
        throw new IOException(execResult.getException());
    }
}
 
开发者ID:ctco,项目名称:gradle-mobile-plugin,代码行数:9,代码来源:IosProvisioningUtil.java

示例9: exec

import org.apache.commons.exec.CommandLine; //导入方法依赖的package包/类
/**
 * Launches the given command in a new process, in the given working
 * directory.
 * 
 * @param cmd
 *            the command line to execute as an array of strings
 * @param env
 *            the environment to set as an array of strings
 * @param workingDir
 *            working directory where the command should run
 * @throws IOException
 *             forwarded from the exec method of the command launcher
 */
public Process exec(final CommandLine cmd, final Map env,
        final File workingDir) throws IOException {
    if (workingDir == null) {
        return exec(cmd, env);
    }

    // Use cmd.exe to change to the specified directory before running
    // the command
    CommandLine newCmd = new CommandLine("cmd");
    newCmd.addArgument("/c");
    newCmd.addArguments(cmd.toStrings());

    return exec(newCmd, env);
}
 
开发者ID:deim0s,项目名称:XWBEx,代码行数:28,代码来源:WinNTCommandLauncher.java

示例10: runOnMaster

import org.apache.commons.exec.CommandLine; //导入方法依赖的package包/类
public static ExecuteResult runOnMaster(ExecExceptionHandling exceptionHandling, String executable,
		String... arguments) throws ExecuteException, IOException {
	CommandLine cmdLine = new CommandLine(executable);
	cmdLine.addArguments(arguments);
	ExecuteResult result = runOnMaster(cmdLine, exceptionHandling);
	return result;
}
 
开发者ID:Zuehlke,项目名称:SHMACK,代码行数:8,代码来源:ShmackUtils.java

示例11: runOnLocalhost

import org.apache.commons.exec.CommandLine; //导入方法依赖的package包/类
public static ExecuteResult runOnLocalhost(ExecExceptionHandling exceptionHandling, String executable,
		String... arguments) throws ExecuteException, IOException {
	CommandLine cmdLine = new CommandLine(executable);
	cmdLine.addArguments(arguments);
	ExecuteResult result = runOnLocalhost(exceptionHandling, cmdLine);
	return result;

}
 
开发者ID:Zuehlke,项目名称:SHMACK,代码行数:9,代码来源:ShmackUtils.java

示例12: executeSparkRemote

import org.apache.commons.exec.CommandLine; //导入方法依赖的package包/类
public void executeSparkRemote(String... sparkMainArguments) throws Exception {
	final File hdfsTestJobFolder = getHdfsTestJobFolder(testClass, testcaseId);
	LOGGER.info("HDFS Working Directory: hdfs://hdfs" + hdfsTestJobFolder.getAbsolutePath());
	LOGGER.info("Deleting old status and result files...");
	ShmackUtils.deleteInHdfs(hdfsTestJobFolder);
	final File hdfsJarFile = syncFatJatToHdfs();

	String hdfsJarFileURL = ShmackUtils.getHdfsURL(hdfsJarFile);

	LOGGER.info("Writing initial Job status to HDFS...");
	ShmackUtils.writeStringToHdfs(getHdfsStatusFile(testClass, testcaseId), SUBMITTED);

	LOGGER.info("Submitting Spark-Job...");
	CommandLine cmdLine = new CommandLine("bash");
	cmdLine.addArgument(ShmackUtils.determineScriptDir() + "submit-spark-job.sh");
	cmdLine.addArgument("-Dspark.mesos.coarse=true");
	cmdLine.addArgument("--driver-cores");
	cmdLine.addArgument(String.valueOf(getDriverCores()));
	cmdLine.addArgument("--driver-memory");
	cmdLine.addArgument(getDriverMemory());
	cmdLine.addArgument("--class");
	cmdLine.addArgument(testClass.getName());
	cmdLine.addArgument(hdfsJarFileURL);
	cmdLine.addArguments(sparkMainArguments);
	ExecuteResult result = ShmackUtils.runOnLocalhost(ExecExceptionHandling.THROW_EXCEPTION_IF_EXIT_CODE_NOT_0,
			cmdLine);
	LOGGER.info(result.getStandardOutput());
}
 
开发者ID:Zuehlke,项目名称:SHMACK,代码行数:29,代码来源:RemoteSparkTestRunner.java

示例13: execCordova

import org.apache.commons.exec.CommandLine; //导入方法依赖的package包/类
void execCordova(String action, File dir, String... args) {
    CommandLine commandLine = new CommandLine(cordovaExec);
    commandLine.addArguments(args);
    exec(action, dir, commandLine);
}
 
开发者ID:spirylics,项目名称:web2app,代码行数:6,代码来源:Web2AppMojo.java

示例14: isGitDir

import org.apache.commons.exec.CommandLine; //导入方法依赖的package包/类
public static boolean isGitDir(File dir) {
    CommandLine commandLine = new CommandLine("git");
    commandLine.addArguments(new String[] {"rev-parse", "--is-inside-work-tree"}, false);
    ExecResult execResult = ExecUtil.execCommand(commandLine, dir, null, true, false);
    return execResult.isSuccess();
}
 
开发者ID:ctco,项目名称:gradle-mobile-plugin,代码行数:7,代码来源:GitUtil.java

示例15: fetchAll

import org.apache.commons.exec.CommandLine; //导入方法依赖的package包/类
public static ExecResult fetchAll(File dir) {
    CommandLine command = new CommandLine("git");
    command.addArguments(new String[]{"fetch", "--all", "--verbose"}, false);
    return ExecUtil.execCommand(command, dir, null, true, false);
}
 
开发者ID:ctco,项目名称:gradle-mobile-plugin,代码行数:6,代码来源:GitUtil.java


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