当前位置: 首页>>代码示例>>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;未经允许,请勿转载。