本文整理汇总了Java中org.zeroturnaround.exec.ProcessExecutor.start方法的典型用法代码示例。如果您正苦于以下问题:Java ProcessExecutor.start方法的具体用法?Java ProcessExecutor.start怎么用?Java ProcessExecutor.start使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.zeroturnaround.exec.ProcessExecutor
的用法示例。
在下文中一共展示了ProcessExecutor.start方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testDataIsFlushedToProcessWithANonEndingInputStream
import org.zeroturnaround.exec.ProcessExecutor; //导入方法依赖的package包/类
@Test
public void testDataIsFlushedToProcessWithANonEndingInputStream() throws Exception {
String str = "Tere Minu Uus vihik " + System.nanoTime();
// Setup InputStream that will block on a read()
PipedOutputStream pos = new PipedOutputStream();
PipedInputStream pis = new PipedInputStream(pos);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ProcessExecutor exec = new ProcessExecutor("java", "-cp", "target/test-classes", PrintInputToOutput.class.getName());
exec.redirectInput(pis).redirectOutput(baos);
StartedProcess startedProcess = exec.start();
pos.write(str.getBytes());
pos.write("\n\n\n".getBytes()); // PrintInputToOutput processes at most 3 lines
// Assert that we don't get a TimeoutException
startedProcess.getFuture().get(5, TimeUnit.SECONDS);
Assert.assertEquals(str, baos.toString());
}
示例2: frontendStart
import org.zeroturnaround.exec.ProcessExecutor; //导入方法依赖的package包/类
private void frontendStart() throws IOException {
ProcessExecutor processExecutor = new ProcessExecutor()
.directory(new File("frontend"))
.command("yarn", "start")
.redirectOutput(Slf4jStream.of(LoggerFactory.getLogger("yarn")).asInfo())
.redirectError(Slf4jStream.of(LoggerFactory.getLogger("yarn")).asError());
if (isWindows()) {
processExecutor = processExecutor.command("cmd", "/c", "yarn", "start");
}
processExecutor.start();
}
示例3: yarnStart
import org.zeroturnaround.exec.ProcessExecutor; //导入方法依赖的package包/类
private void yarnStart(File frontendDir) throws IOException {
ProcessExecutor process = command("yarn", "start")
.directory(frontendDir)
.redirectOutput(Slf4jStream.of(LoggerFactory.getLogger("yarn")).asInfo())
.redirectError(Slf4jStream.of(LoggerFactory.getLogger("yarn")).asError());
process.start();
}
示例4: call
import org.zeroturnaround.exec.ProcessExecutor; //导入方法依赖的package包/类
@Override
public StartedProcess call() throws RabbitMqCommandException {
List<String> fullCommand = new ArrayList<>(arguments);
fullCommand.add(0, executableFile.toString());
Slf4jStream loggingStream = Slf4jStream.of(processOutputLogger);
LoggingProcessListener loggingListener = new LoggingProcessListener(processOutputLogger);
ProcessExecutor processExecutor = processExecutorFactory.createInstance()
.environment(config.getEnvVars())
.directory(config.getAppFolder())
.command(fullCommand)
.destroyOnExit()
.addListener(loggingListener) // Logs process events (like start, stop...)
.addListener(eventsListener) // Notifies asynchronously of process events (start/finish/stop)
.redirectError(loggingStream.as(stdErrLogLevel)) // Logging for output made to STDERR
.redirectOutput(loggingStream.as(stdOutLogLevel)) // Logging for output made to STDOUT
.redirectOutputAlsoTo(outputStream) // Pipe stdout to this stream for the application to process
.redirectErrorAlsoTo(errorOutputStream) // Pipe stderr to this stream for the application to process
.readOutput(storeOutput); // Store the output in the ProcessResult as well.
try {
return processExecutor.start();
} catch (IOException e) {
throw new RabbitMqCommandException("Failed to execute: " + StringUtils.join(fullCommand, " "), e);
}
}
示例5: testRedirectPipedInputStream
import org.zeroturnaround.exec.ProcessExecutor; //导入方法依赖的package包/类
@Test
public void testRedirectPipedInputStream() throws Exception {
// Setup InputStream that will block on a read()
PipedOutputStream pos = new PipedOutputStream();
PipedInputStream pis = new PipedInputStream(pos);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ProcessExecutor exec = new ProcessExecutor("java", "-cp", "target/test-classes", PrintArguments.class.getName());
exec.redirectInput(pis);
StartedProcess startedProcess = exec.start();
// Assert that we don't get a TimeoutException
startedProcess.getFuture().get(5, TimeUnit.SECONDS);
}
示例6: startProcess
import org.zeroturnaround.exec.ProcessExecutor; //导入方法依赖的package包/类
private StartedProcess startProcess() throws IOException {
ProcessExecutor processExecutor = buildProcessExecutor();
return processExecutor.start();
}