當前位置: 首頁>>代碼示例>>Java>>正文


Java DefaultExecutor.setExitValue方法代碼示例

本文整理匯總了Java中org.apache.commons.exec.DefaultExecutor.setExitValue方法的典型用法代碼示例。如果您正苦於以下問題:Java DefaultExecutor.setExitValue方法的具體用法?Java DefaultExecutor.setExitValue怎麽用?Java DefaultExecutor.setExitValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.exec.DefaultExecutor的用法示例。


在下文中一共展示了DefaultExecutor.setExitValue方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: runMavenCommand

import org.apache.commons.exec.DefaultExecutor; //導入方法依賴的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: checkDot

import org.apache.commons.exec.DefaultExecutor; //導入方法依賴的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

示例3: AbstractCppcheckCommand

import org.apache.commons.exec.DefaultExecutor; //導入方法依賴的package包/類
public AbstractCppcheckCommand(IConsole console, String[] defaultArguments,
		long timeout, String binaryPath) {

	this.binaryPath = binaryPath;
	this.console = console;
	this.defaultArguments = defaultArguments;
	
	executor = new DefaultExecutor();

	// all modes of operation returns 0 when no error occured,
	executor.setExitValue(0);

	watchdog = new ExecuteWatchdog(timeout);
	executor.setWatchdog(watchdog);

	out = new ByteArrayOutputStream();
	err = new ByteArrayOutputStream();

	processStdOut = new LineFilterOutputStream(new TeeOutputStream(out,
			console.getConsoleOutputStream(false)), DEFAULT_CHARSET);
	processStdErr = new LineFilterOutputStream(new TeeOutputStream(err,
			console.getConsoleOutputStream(true)), DEFAULT_CHARSET);
	
}
 
開發者ID:kwin,項目名稱:cppcheclipse,代碼行數:25,代碼來源:AbstractCppcheckCommand.java

示例4: executeProcess

import org.apache.commons.exec.DefaultExecutor; //導入方法依賴的package包/類
/**
 * Creates a process and logs the output
 */
public void executeProcess(String[] cmd, String logKey, ProcessResult result,
    Map<String, String> additionalEnvVars, File workingDir) {

  Map<String, String> env = getEnvVars(cmd, additionalEnvVars);
  logger.info(format("%s Cmd: %s, Additional Env Vars: %s", logKey,
      String.join(" ", cmd), additionalEnvVars));

  try {
    CommandLine cmdLine = new CommandLine(cmd[0]);
    // add rest of cmd string[] as arguments
    for (int i = 1; i < cmd.length; i++) {
      // needs the quote handling=false or else doesn't work
      // http://www.techques.com/question/1-5080109/How-to-execute--bin-sh-with-commons-exec?
      cmdLine.addArgument(cmd[i], false);
    }
    DefaultExecutor executor = new DefaultExecutor();
    executor.setExitValue(0);
    executor.setWatchdog(new ExecuteWatchdog(timeoutInSeconds * 1000));
    executor.setStreamHandler(new OutputHandler(logger, logKey, result));
    if (workingDir != null) {
      executor.setWorkingDirectory(workingDir);
    }
    result.setResultCode(executor.execute(cmdLine, env));

    // set fault to last error if fault map is empty
    if (result.getResultCode() != 0 && result.getFaultMap().keySet().size() < 1) {
      result.getFaultMap().put("ERROR", result.getLastError());
    }

  } catch (ExecuteException ee) {
    logger.error(logKey + ee);
    result.setResultCode(ee.getExitValue());
  } catch (IOException e) {
    logger.error(e);
    result.setResultCode(1);
  }

}
 
開發者ID:oneops,項目名稱:oneops,代碼行數:42,代碼來源:ProcessRunner.java

示例5: startAppiumServer

import org.apache.commons.exec.DefaultExecutor; //導入方法依賴的package包/類
private void startAppiumServer() {
    try {
        // Kill any node servers that may be running
        stopAppiumServer();

        log.info("START APPIUM");

        CommandLine command = new CommandLine(ConfigurationManager.getInstance().getMobileAppiumNodeServerCommandLine());

        for (String argument : ConfigurationManager.getInstance().getMobileAppiumNodeServerArguments()) {
            command.addArgument(argument);
        }

        DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
        DefaultExecutor executor = new DefaultExecutor();
        executor.setExitValue(1);

        executor.execute(command, resultHandler);
        Thread.sleep(10000);

        log.info("APPIUM server started successfully.");

    } catch (IOException e) {
        log.error("Appium Server Failed to start.", e);
    } catch (InterruptedException ie) {
        log.error("Appium Server wait failed.", ie);
    }
}
 
開發者ID:AgileTestingFramework,項目名稱:atf-toolbox-java,代碼行數:29,代碼來源:MobileAutomationManager.java

示例6: renderGraph

import org.apache.commons.exec.DefaultExecutor; //導入方法依賴的package包/類
/**
 * Call graphviz-dot to convert the .dot-file to a rendered graph.
    *
    * The file extension of the specified result file is being used as the filetype
    * of the rendering.
 *
 * @param dotfile The dot {@code File}  used for the graph generation
    * @param resultfile The {@code File} to which should be written
 *
 * @throws IOException if writing the resulting graph fails or other I/O
 * 			problems occur
 */
public static void renderGraph(File dotfile, File resultfile) throws IOException {
	// call graphviz-dot via commons-exec
	CommandLine cmdLine = new CommandLine(DOT_EXE);
	cmdLine.addArgument("-T" + StringUtils.substringAfterLast(resultfile.getAbsolutePath(), "."));
	cmdLine.addArgument(dotfile.getAbsolutePath());
	DefaultExecutor executor = new DefaultExecutor();
	executor.setExitValue(0);
	ExecuteWatchdog watchdog = new ExecuteWatchdog(60000);
	executor.setWatchdog(watchdog);
	try {
		try (FileOutputStream out2 = new FileOutputStream(resultfile)) {
			executor.setStreamHandler(new PumpStreamHandler(out2, System.err));
			int exitValue = executor.execute(cmdLine);
			if(exitValue != 0) {
				throw new IOException("Could not convert graph to dot, had exit value: " + exitValue + "!");
			}
		}
	} catch (IOException e) {
		// if something went wrong the file should not be left behind...
		if(!resultfile.delete()) {
			System.out.println("Could not delete file " + resultfile);
		}

		throw e;
	}
}
 
開發者ID:centic9,項目名稱:commons-dost,代碼行數:39,代碼來源:DotUtils.java

示例7: getDefaultExecutor

import org.apache.commons.exec.DefaultExecutor; //導入方法依賴的package包/類
private static DefaultExecutor getDefaultExecutor(File dir, int expectedExit, long timeout) {
	DefaultExecutor executor = new DefaultExecutor();
	if(expectedExit != -1) {
		executor.setExitValue(expectedExit);
	} else {
		executor.setExitValues(null);
	}

	ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout);
	executor.setWatchdog(watchdog);
	executor.setWorkingDirectory(dir);
	return executor;
}
 
開發者ID:centic9,項目名稱:commons-dost,代碼行數:14,代碼來源:ExecutionHelper.java

示例8: decodeXWMA

import org.apache.commons.exec.DefaultExecutor; //導入方法依賴的package包/類
public static void decodeXWMA(String location) throws ExecuteException, IOException
{
	String source = Wav.class.getProtectionDomain().getCodeSource().getLocation().getPath();
       source = URLDecoder.decode(source, "utf-8");
       source = (new File(source)).getParent();
       
       File xwma = new File(location);
       int ext = xwma.getName().indexOf('.');
       File wav = new File(xwma.getParentFile(), (xwma.getName().substring(0, ext)) + ".wav");
       
       CommandLine command = new CommandLine(new File(source, "xWMAEncode.exe"));
       command.addArgument("${Input_File}", true);
       command.addArgument("${Output_File}", true);
       
       Map<Object, Object> subMap = new HashMap<Object, Object>();
       subMap.put("Input_File", xwma.getAbsolutePath());
       subMap.put("Output_File", wav.getAbsolutePath());
       command.setSubstitutionMap(subMap);
       
       DefaultExecutor executor = new DefaultExecutor();
       PumpStreamHandler streamHandler = new PumpStreamHandler(new NullOutputStream());
       executor.setStreamHandler(streamHandler);
       //executor.setWorkingDirectory(new File(source));
       executor.setExitValue(0);
       executor.execute(command);
       
       xwma.delete();
}
 
開發者ID:deim0s,項目名稱:XWBEx,代碼行數:29,代碼來源:Wav.java

示例9: main

import org.apache.commons.exec.DefaultExecutor; //導入方法依賴的package包/類
public static void main(String[] args) throws ExecuteException, IOException, InterruptedException
    {
        CommandLine command = new CommandLine("/bin/bash");
        command.addArgument("-c", false);
        command.addArgument("iperf3 -t 30 -c iperf.scottlinux.com >> output.txt", false);
        
        //Process process = Runtime.getRuntime().exec(new String[]{"bash", "-c", "iperf3 -t 60 -c localhost"});
       // System.out.println(new Mirror().on(process).get().field("pid"));
        
        //process.waitFor();
        
//        System.out.println(process.exitValue());
//        ManagementFactory.getRuntimeMXBean().getName();  
//        System.out.println(IOUtils.readLines(process.getInputStream()));
        
        //String command = "iperf3 -t 30 -c iperf.scottlinux.com";
        
        ExecuteWatchdog watchdog = new ExecuteWatchdog(10);
        
        final DefaultExecutor executor = new DefaultExecutor();
        executor.setStreamHandler(new PumpStreamHandler());
        executor.setExitValue(1);
        
        executor.execute(command, new ExecuteResultHandler()
        {
            @Override
            public void onProcessFailed(ExecuteException e)
            {
                e.printStackTrace();
            }
            
            @Override
            public void onProcessComplete(int exitValue)
            {
                System.out.println(exitValue);
            }
        });
    }
 
開發者ID:alessandroleite,項目名稱:dohko,代碼行數:39,代碼來源:CommandExample.java

示例10: launchProcess

import org.apache.commons.exec.DefaultExecutor; //導入方法依賴的package包/類
/**
 * If it is backend, please set resultHandler, such as DefaultExecuteResultHandler
 * If it is frontend, ByteArrayOutputStream.toString will return the calling result
 * <p>
 * This function will ignore whether the command is successfully executed or not
 *
 * @param command       command to be executed
 * @param environment   env vars
 * @param workDir       working directory
 * @param resultHandler exec result handler
 * @return output stream
 * @throws IOException
 */
@Deprecated
public static ByteArrayOutputStream launchProcess(
        String command, final Map environment, final String workDir,
        ExecuteResultHandler resultHandler) throws IOException {

    String[] cmdlist = command.split(" ");

    CommandLine cmd = new CommandLine(cmdlist[0]);
    for (String cmdItem : cmdlist) {
        if (!StringUtils.isBlank(cmdItem)) {
            cmd.addArgument(cmdItem);
        }
    }

    DefaultExecutor executor = new DefaultExecutor();

    executor.setExitValue(0);
    if (!StringUtils.isBlank(workDir)) {
        executor.setWorkingDirectory(new File(workDir));
    }

    ByteArrayOutputStream out = new ByteArrayOutputStream();

    PumpStreamHandler streamHandler = new PumpStreamHandler(out, out);
    executor.setStreamHandler(streamHandler);

    try {
        if (resultHandler == null) {
            executor.execute(cmd, environment);
        } else {
            executor.execute(cmd, environment, resultHandler);
        }
    } catch (ExecuteException ignored) {
    }

    return out;

}
 
開發者ID:alibaba,項目名稱:jstorm,代碼行數:52,代碼來源:JStormUtils.java

示例11: launchProcess

import org.apache.commons.exec.DefaultExecutor; //導入方法依賴的package包/類
/**
 * If it is backend, please set resultHandler, such as DefaultExecuteResultHandler
 * If it is frontend, ByteArrayOutputStream.toString get the result
 * 
 * This function don't care whether the command is successfully or not
 * 
 * @param command
 * @param environment
 * @param workDir
 * @param resultHandler
 * @return
 * @throws IOException
 */
public static ByteArrayOutputStream launchProcess(String command, final Map environment,
		final String workDir, ExecuteResultHandler resultHandler)
		throws IOException {

	String[] cmdlist = command.split(" ");

	CommandLine cmd = new CommandLine(cmdlist[0]);
	for (String cmdItem : cmdlist) {
		if (StringUtils.isBlank(cmdItem) == false) {
			cmd.addArgument(cmdItem);
		}
	}

	DefaultExecutor executor = new DefaultExecutor();

	executor.setExitValue(0);
	if (StringUtils.isBlank(workDir) == false) {
		executor.setWorkingDirectory(new File(workDir));
	}

	ByteArrayOutputStream out = new ByteArrayOutputStream();

	PumpStreamHandler streamHandler = new PumpStreamHandler(out, out);
	if (streamHandler != null) {
		executor.setStreamHandler(streamHandler);
	}

	try {
		if (resultHandler == null) {
			executor.execute(cmd, environment);
		} else {
			executor.execute(cmd, environment, resultHandler);
		}
	}catch(ExecuteException e) {
		
		// @@@@ 
		// failed to run command
	}

	return out;

}
 
開發者ID:zhangjunfang,項目名稱:jstorm-0.9.6.3-,代碼行數:56,代碼來源:JStormUtils.java

示例12: launchProcess

import org.apache.commons.exec.DefaultExecutor; //導入方法依賴的package包/類
/**
 * If it is backend, please set resultHandler, such as DefaultExecuteResultHandler If it is frontend, ByteArrayOutputStream.toString get the result
 * <p/>
 * This function don't care whether the command is successfully or not
 * 
 * @param command
 * @param environment
 * @param workDir
 * @param resultHandler
 * @return
 * @throws IOException
 */
public static ByteArrayOutputStream launchProcess(String command, final Map environment, final String workDir, ExecuteResultHandler resultHandler)
        throws IOException {

    String[] cmdlist = command.split(" ");

    CommandLine cmd = new CommandLine(cmdlist[0]);
    for (String cmdItem : cmdlist) {
        if (StringUtils.isBlank(cmdItem) == false) {
            cmd.addArgument(cmdItem);
        }
    }

    DefaultExecutor executor = new DefaultExecutor();

    executor.setExitValue(0);
    if (StringUtils.isBlank(workDir) == false) {
        executor.setWorkingDirectory(new File(workDir));
    }

    ByteArrayOutputStream out = new ByteArrayOutputStream();

    PumpStreamHandler streamHandler = new PumpStreamHandler(out, out);
    if (streamHandler != null) {
        executor.setStreamHandler(streamHandler);
    }

    try {
        if (resultHandler == null) {
            executor.execute(cmd, environment);
        } else {
            executor.execute(cmd, environment, resultHandler);
        }
    } catch (ExecuteException e) {

        // @@@@
        // failed to run command
    }

    return out;

}
 
開發者ID:kkllwww007,項目名稱:jstrom,代碼行數:54,代碼來源:JStormUtils.java

示例13: execute

import org.apache.commons.exec.DefaultExecutor; //導入方法依賴的package包/類
/**
 * Executes the current NPM using the given binary file.
 *
 * @param binary the program to run
 * @param args   the arguments
 * @return the execution exit status
 * @throws MojoExecutionException if the execution failed
 */
public int execute(File binary, String... args) throws MojoExecutionException {
    File destination = getNPMDirectory();
    if (!destination.isDirectory()) {
        throw new IllegalStateException("NPM " + this.npmName + " not installed");
    }

    CommandLine cmdLine = new CommandLine(node.getNodeExecutable());

    if (binary == null) {
        throw new IllegalStateException("Cannot execute NPM " + this.npmName + " - the given binary is 'null'.");
    }

    if (!binary.isFile()) {
        throw new IllegalStateException("Cannot execute NPM " + this.npmName + " - the given binary does not " +
                "exist: " + binary.getAbsoluteFile() + ".");
    }

    // NPM is launched using the main file.
    cmdLine.addArgument(binary.getAbsolutePath(), false);
    for (String arg : args) {
        cmdLine.addArgument(arg, this.handleQuoting);
    }

    DefaultExecutor executor = new DefaultExecutor();

    executor.setExitValue(0);

    errorStreamFromLastExecution = new LoggedOutputStream(log, true, true);
    outputStreamFromLastExecution = new LoggedOutputStream(log, false, registerOutputStream);

    PumpStreamHandler streamHandler = new PumpStreamHandler(
            outputStreamFromLastExecution,
            errorStreamFromLastExecution);

    executor.setStreamHandler(streamHandler);
    executor.setWorkingDirectory(node.getWorkDir());
    log.info("Executing " + cmdLine.toString() + " from " + executor.getWorkingDirectory().getAbsolutePath());

    try {
        return executor.execute(cmdLine, extendEnvironmentWithNodeInPath(node));
    } catch (IOException e) {
        throw new MojoExecutionException("Error during the execution of the NPM " + npmName, e);
    }

}
 
開發者ID:wisdom-framework,項目名稱:wisdom,代碼行數:54,代碼來源:NPM.java


注:本文中的org.apache.commons.exec.DefaultExecutor.setExitValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。