當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。