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


Java ExecuteStreamHandler类代码示例

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


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

示例1: createStreamHandler

import org.apache.commons.exec.ExecuteStreamHandler; //导入依赖的package包/类
private ExecuteStreamHandler createStreamHandler() throws IOException {
  out = new ByteArrayOutputStream();
  err = new ByteArrayOutputStream();
  PipedOutputStream outPiped = new PipedOutputStream();
  InputStream inPiped = new PipedInputStream(outPiped);
  in = outPiped;

  TeeOutputStream teeOut = new TeeOutputStream(out, System.out);
  TeeOutputStream teeErr = new TeeOutputStream(err, System.err);

  return new PumpStreamHandler(teeOut, teeErr, inPiped);
}
 
开发者ID:SonarSource,项目名称:sonarlint-cli,代码行数:13,代码来源:CommandExecutor.java

示例2: run

import org.apache.commons.exec.ExecuteStreamHandler; //导入依赖的package包/类
/**
 * run a command with the out, err and in.
 *
 * @param cmd
 *            the command line
 * @param out
 *            the console outputstream
 * @param err
 *            the error outputstream
 * @param in
 *            the inputstream
 * @param workdir
 *            the working dir
 * @return the result
 * @throws IOException
 *             throw IOException if error
 */
public static int run(String cmd, OutputStream out, OutputStream err, InputStream in, String workdir)
		throws IOException {

	try {

		CommandLine cmdLine = CommandLine.parse(cmd);

		ExecuteStreamHandler stream = new PumpStreamHandler(out, err, in);
		int[] exit = new int[512];
		for (int i = 0; i < exit.length; i++) {
			exit[i] = i - 256;
		}
		executor.setExitValues(exit);

		executor.setStreamHandler(stream);
		if (!X.isEmpty(workdir)) {
			executor.setWorkingDirectory(new File(workdir));
		}

		// ExecuteWatchdog watchdog = new ExecuteWatchdog(60000);
		// executor.setWatchdog(watchdog);
		// watchdog.destroyProcess();

		return executor.execute(cmdLine);
	} catch (IOException e) {
		log.error("cmd=" + cmd, e);
		throw e;
	}
}
 
开发者ID:giiwa,项目名称:giiwa,代码行数:47,代码来源:Shell.java

示例3: bash

import org.apache.commons.exec.ExecuteStreamHandler; //导入依赖的package包/类
/**
 * using bash to execute the lines.
 *
 * @param lines
 *            the command lines
 * @param out
 *            the output stream
 * @param err
 *            the error stream
 * @param in
 *            the input stream
 * @param workdir
 *            the workdir
 * @return the int
 * @throws IOException
 *             throw IOException if error
 */
public static int bash(String lines, OutputStream out, OutputStream err, InputStream in, String workdir)
		throws IOException {

	File f = new File(UID.id(lines).toLowerCase() + ".bash");

	try {
		if (!X.isEmpty(workdir)) {
			lines = "cd " + workdir + ";" + lines;
		}
		FileUtils.writeStringToFile(f, lines);

		// Execute the file we just creted. No flags are due if it is
		// executed with bash directly
		CommandLine commandLine = CommandLine.parse("bash " + f.getCanonicalPath());

		ExecuteStreamHandler stream = new PumpStreamHandler(out, err, in);

		DefaultExecutor executor = new DefaultExecutor();
		int[] exit = new int[3];
		for (int i = 0; i < exit.length; i++) {
			exit[i] = i - 1;
		}
		executor.setExitValues(exit);

		executor.setStreamHandler(stream);
		if (!X.isEmpty(workdir)) {
			executor.setWorkingDirectory(new File(workdir));
		}

		return executor.execute(commandLine);

	} catch (IOException e) {
		log.error("lines=" + lines, e);
		throw e;
	} finally {
		f.delete();
	}
}
 
开发者ID:giiwa,项目名称:giiwa,代码行数:56,代码来源:Shell.java

示例4: execute

import org.apache.commons.exec.ExecuteStreamHandler; //导入依赖的package包/类
public void execute(final Application application, ExecuteResultHandler executeResultHandler, ExecuteStreamHandler streamHandler) throws ExecuteException, IOException
{
    final String commandLine = application.getCommandLine();
    
    DefaultExecutor executor = new DefaultExecutor();
    
    CommandLine command = new CommandLine("/bin/sh");
    command.addArgument("-c", false);
    command.addArgument(commandLine, false);
    executor.setStreamHandler(streamHandler);
    executor.execute(command, System.getenv(), executeResultHandler);
    
    LOG.debug("Launched the execution of task: [{}], uuid: [{}]", commandLine, application.getId());
}
 
开发者ID:alessandroleite,项目名称:dohko,代码行数:15,代码来源:Worker.java

示例5: setStreamHandler

import org.apache.commons.exec.ExecuteStreamHandler; //导入依赖的package包/类
/**
 * The stream handler is transmitted in the constructor.
 * @throws UnsupportedOperationException
 */
@Override
public void setStreamHandler(ExecuteStreamHandler streamHandler) {
	throw new UnsupportedOperationException();
}
 
开发者ID:Zenika,项目名称:varnishtest-exec,代码行数:9,代码来源:VarnishtestExecutor.java

示例6: executeProgram

import org.apache.commons.exec.ExecuteStreamHandler; //导入依赖的package包/类
/**
 * 
 * @param printJobTimeout
 *            the printJobTimeout (ms) before the watchdog terminates the
 *            print process
 * @param printInBackground
 *            printing done in the background or blocking
 * @param streamHandler
 * @return a print result handler (implementing a future)
 * @throws IOException
 *             the test failed
 */
public static PrintResultHandler executeProgram(CommandLine commandLine, long printJobTimeout, boolean printInBackground,
		int successExitValue, ExecuteStreamHandler streamHandler) throws IOException {
	return executeProgram(commandLine, null, printJobTimeout, printInBackground, successExitValue, streamHandler);
}
 
开发者ID:GluuFederation,项目名称:oxCore,代码行数:17,代码来源:ProcessHelper.java


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