本文整理汇总了Java中org.zeroturnaround.exec.stream.slf4j.Slf4jStream类的典型用法代码示例。如果您正苦于以下问题:Java Slf4jStream类的具体用法?Java Slf4jStream怎么用?Java Slf4jStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Slf4jStream类属于org.zeroturnaround.exec.stream.slf4j包,在下文中一共展示了Slf4jStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.zeroturnaround.exec.stream.slf4j.Slf4jStream; //导入依赖的package包/类
@Override
public void execute(final String[] arguments, final File directory) {
LOGGER.info(String.format("Execute maven at '%s': %s", directory, Arrays.toString(arguments)));
try {
final List<String> argumentsAsList = Lists.newArrayList(Arrays.asList(arguments));
argumentsAsList.add(0, getMavenCommand());
if (LOGGER.isDebugEnabled()) {
argumentsAsList.add("-e");
}
new ProcessExecutor() //
.command(argumentsAsList) //
.directory(directory) //
.redirectOutput(Slf4jStream.of(LOGGER).asDebug()) //
.redirectError(Slf4jStream.of(LOGGER).asError()) //
.execute();
} catch (final Exception exception) {
throw new MavenExecutionException(exception);
}
}
示例2: taskkill
import org.zeroturnaround.exec.stream.slf4j.Slf4jStream; //导入依赖的package包/类
/**
* Sends the destroy signal to this process.
*
* @param forceful <code>true</code> if this process should be destroyed forcefully.
* @return <code>true</code> if this process got the signal, <code>false</code> if the process was not found (any more).
*
* @throws IOException on IO error.
* @throws InterruptedException if interrupted.
*/
public boolean taskkill(boolean forceful) throws IOException, InterruptedException {
try {
new ProcessExecutor()
.commandSplit(String.format("taskkill%s%s /PID %d", includeChildren ? " /T" : "", forceful ? " /F" : "", pid))
.redirectOutput(Slf4jStream.ofCaller().asDebug()).exitValueNormal().executeNoTimeout();
return true;
}
catch (InvalidExitValueException e) {
if (e.getExitValue() == EXIT_CODE_COULD_NOT_BE_TERMINATED) {
// Process could be either alive or not, if it's not alive we don't want to throw an exception
if (isAlive()) {
throw e; // process is still alive
}
return false; // process is stopped but but not because of us
}
if (e.getExitValue() == EXIT_CODE_NO_SUCH_PROCESS) {
return false;
}
throw e;
}
}
示例3: isAlive
import org.zeroturnaround.exec.stream.slf4j.Slf4jStream; //导入依赖的package包/类
public boolean isAlive() throws IOException, InterruptedException {
try {
new ProcessExecutor()
.commandSplit(String.format("kill -0 %d", pid)).readOutput(true)
.redirectOutput(Slf4jStream.ofCaller().asTrace())
.setMessageLogger(MessageLoggers.TRACE)
.exitValueNormal()
.executeNoTimeout();
return true;
}
catch (InvalidExitValueException e) {
if (isNoSuchProcess(e)) {
return false;
}
throw e;
}
}
示例4: loadAgent
import org.zeroturnaround.exec.stream.slf4j.Slf4jStream; //导入依赖的package包/类
private static void loadAgent(final File tempAgentJar, final String pid) throws Exception {
if (DynamicInstrumentationReflections.isBeforeJava9()) {
DynamicInstrumentationLoadAgentMain.loadAgent(pid, tempAgentJar.getAbsolutePath());
} else {
//-Djdk.attach.allowAttachSelf https://www.bountysource.com/issues/45231289-self-attach-fails-on-jdk9
//workaround this limitation by attaching from a new process
final File loadAgentJar = createTempJar(DynamicInstrumentationLoadAgentMain.class, false);
final String javaExecutable = getJavaHome() + File.separator + "bin" + File.separator + "java";
final List<String> command = new ArrayList<String>();
command.add(javaExecutable);
command.add("-classpath");
command.add(loadAgentJar.getAbsolutePath()); //tools.jar not needed since java9
command.add(DynamicInstrumentationLoadAgentMain.class.getName());
command.add(pid);
command.add(tempAgentJar.getAbsolutePath());
new ProcessExecutor().command(command)
.destroyOnExit()
.exitValueNormal()
.redirectOutput(Slf4jStream.of(DynamicInstrumentationLoader.class).asInfo())
.redirectError(Slf4jStream.of(DynamicInstrumentationLoader.class).asWarn())
.execute();
}
}
示例5: frontendStart
import org.zeroturnaround.exec.stream.slf4j.Slf4jStream; //导入依赖的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();
}
示例6: yarnStart
import org.zeroturnaround.exec.stream.slf4j.Slf4jStream; //导入依赖的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();
}
示例7: yarnInstall
import org.zeroturnaround.exec.stream.slf4j.Slf4jStream; //导入依赖的package包/类
private void yarnInstall(File frontendDir) throws InterruptedException, TimeoutException, IOException {
command("yarn", "install")
.directory(frontendDir)
.redirectOutput(Slf4jStream.of(LoggerFactory.getLogger("yarn")).asInfo())
.redirectError(Slf4jStream.of(LoggerFactory.getLogger("yarn")).asError())
.exitValueNormal()
.execute();
}
示例8: getErlangVersion
import org.zeroturnaround.exec.stream.slf4j.Slf4jStream; //导入依赖的package包/类
/**
* @return a String representing the Erlang version, such as {@code "18.2.1"}
* @throws ErlangShellException if the Erlang command can't be executed or if it exits unexpectedly.
*/
public String getErlangVersion() throws ErlangShellException {
String erlangShell = UNIX_ERL_COMMAND;
Logger processOutputLogger = LoggerFactory.getLogger(
String.format(LOGGER_TEMPLATE, this.getClass().getName(), erlangShell));
Slf4jStream stream = Slf4jStream.of(processOutputLogger);
final ProcessExecutor processExecutor = config.getProcessExecutorFactory().createInstance()
.command(erlangShell, "-noshell", "-eval", "erlang:display(erlang:system_info(otp_release)), halt().")
.timeout(config.getErlangCheckTimeoutInMillis(), TimeUnit.MILLISECONDS)
.redirectError(stream.as(Level.WARN))
.destroyOnExit()
.readOutput(true);
try {
ProcessResult processResult = processExecutor.execute();
int exitValue = processResult.getExitValue();
if (exitValue == 0) {
return processResult.outputUTF8().trim().replaceAll("[\"\\\\n]", ""); // "18.2.1\n" -> "18.2.1"
} else {
throw new ErlangShellException("Erlang exited with status " + exitValue);
}
} catch (IOException | InterruptedException | TimeoutException e) {
throw new ErlangShellException("Exception executing Erlang shell command", e);
}
}
示例9: call
import org.zeroturnaround.exec.stream.slf4j.Slf4jStream; //导入依赖的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);
}
}
示例10: execCommand
import org.zeroturnaround.exec.stream.slf4j.Slf4jStream; //导入依赖的package包/类
private static void execCommand(final String... command) throws Exception {
new ProcessExecutor().command(command)
.destroyOnExit()
.timeout(1, TimeUnit.MINUTES)
.exitValueNormal()
.redirectOutput(Slf4jStream.of(SynchronousChannels.class).asInfo())
.redirectError(Slf4jStream.of(SynchronousChannels.class).asWarn())
.stopper(new ProcessStopper() {
@Override
public void stop(final Process process) {
process.destroy();
}
})
.execute();
}
示例11: isAlive
import org.zeroturnaround.exec.stream.slf4j.Slf4jStream; //导入依赖的package包/类
public boolean isAlive() throws IOException, InterruptedException {
String out = new ProcessExecutor()
.commandSplit(String.format("%s process where ProcessId=%d get ProcessId", wmicPath, pid))
.readOutput(true)
.redirectOutput(Slf4jStream.ofCaller().asTrace())
.setMessageLogger(MessageLoggers.TRACE)
.exitValueNormal()
.executeNoTimeout().outputString();
return out.contains(String.valueOf(pid));
}
示例12: kill
import org.zeroturnaround.exec.stream.slf4j.Slf4jStream; //导入依赖的package包/类
/**
* Sends a signal to this process.
*
* @param signal name of the signal.
* @return <code>true</code> if this process received the signal, <code>false</code> if this process was not found (any more).
*
* @throws IOException on IO error.
* @throws InterruptedException if interrupted.
*/
public boolean kill(String signal) throws IOException, InterruptedException {
try {
new ProcessExecutor()
.commandSplit(String.format("kill -%s %d", signal, pid))
.redirectOutput(Slf4jStream.ofCaller().asDebug()).exitValueNormal().executeNoTimeout();
return true;
}
catch (InvalidExitValueException e) {
if (isNoSuchProcess(e)) {
return false;
}
throw e;
}
}
示例13: executeCommand
import org.zeroturnaround.exec.stream.slf4j.Slf4jStream; //导入依赖的package包/类
public String executeCommand(String... args) {
try {
log.debug("Executing command " + Arrays.asList(args));
return executor().command(args)
.timeout(60, TimeUnit.SECONDS)
.redirectError(Slf4jStream.of(getClass()).asInfo())
.readOutput(true).execute()
.outputUTF8();
} catch (Exception e) {
log.warn("Exception while calling command " + Arrays.asList(args) + ": " + e);
throw new ExternalProcessException(e);
}
}
示例14: runAssertionCheckScript
import org.zeroturnaround.exec.stream.slf4j.Slf4jStream; //导入依赖的package包/类
private int runAssertionCheckScript() throws Exception {
assertTrue(wordAssertScript.exists());
return new ProcessExecutor()
.command(Arrays.asList("cmd", "/C", String.format("\"%s\"", wordAssertScript.getAbsolutePath())))
.redirectOutput(Slf4jStream.of(LOGGER).asInfo())
.redirectError(Slf4jStream.of(LOGGER).asInfo())
.timeout(1L, TimeUnit.MINUTES)
.exitValueAny()
.execute()
.getExitValue();
}
示例15: kill
import org.zeroturnaround.exec.stream.slf4j.Slf4jStream; //导入依赖的package包/类
public void kill() throws Exception {
assertTrue(wordShutdownScript.exists());
new ProcessExecutor()
.command(Arrays.asList("cmd", "/C", String.format("\"%s\"", wordShutdownScript.getAbsolutePath())))
.redirectOutput(Slf4jStream.of(LOGGER).asInfo())
.redirectError(Slf4jStream.of(LOGGER).asInfo())
.timeout(1L, TimeUnit.MINUTES)
.exitValueAny()
.execute()
.getExitValue();
}