本文整理匯總了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;
}
示例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);
}
示例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;
}
示例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;
}
示例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");
}
}
}
}
示例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;
}
}
示例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());
}
}
示例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());
}
}
示例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);
}
示例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;
}
示例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;
}
示例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());
}
示例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);
}
示例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();
}
示例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);
}