本文整理汇总了Java中org.zeroturnaround.exec.InvalidExitValueException类的典型用法代码示例。如果您正苦于以下问题:Java InvalidExitValueException类的具体用法?Java InvalidExitValueException怎么用?Java InvalidExitValueException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InvalidExitValueException类属于org.zeroturnaround.exec包,在下文中一共展示了InvalidExitValueException类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: execute
import org.zeroturnaround.exec.InvalidExitValueException; //导入依赖的package包/类
/**
* Executes this command.
* @param timeout The allowed timeout
* @param unit A time unit
* @return This command
* @throws TimeoutException See {@link ProcessExecutor#execute()}
* @throws InvalidExitValueException See {@link ProcessExecutor#execute()}
* @throws IOException See {@link ProcessExecutor#execute()}
* @throws InterruptedException See {@link ProcessExecutor#execute()}
*/
public Command execute(long timeout, TimeUnit unit)
throws TimeoutException, InvalidExitValueException, IOException,
InterruptedException {
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
final ByteArrayOutputStream errorStream = new ByteArrayOutputStream();
final int exitCode = new ProcessExecutor()
.environment(System.getenv())
.directory(this.directory)
.command(this.parts)
.timeout(timeout, unit)
.redirectOutput(outputStream)
.redirectError(errorStream)
.readOutput(true)
.stopper((process) -> {
process.destroyForcibly();
})
.execute()
.getExitValue();
this.result = new Result(
exitCode,
outputStream,
errorStream
);
return this;
}
开发者ID:jachinte,项目名称:grade-buddy,代码行数:36,代码来源:Command.java
示例2: taskkill
import org.zeroturnaround.exec.InvalidExitValueException; //导入依赖的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;
}
}
开发者ID:zeroturnaround,项目名称:zt-process-killer,代码行数:31,代码来源:WindowsProcess.java
示例3: isAlive
import org.zeroturnaround.exec.InvalidExitValueException; //导入依赖的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;
}
}
开发者ID:zeroturnaround,项目名称:zt-process-killer,代码行数:18,代码来源:UnixProcess.java
示例4: runShellCommand
import org.zeroturnaround.exec.InvalidExitValueException; //导入依赖的package包/类
/**
* Run a shell command synchronously.
*
* @param command command to run and arguments
* @return the stdout output of the command
*/
public static String runShellCommand(String... command) {
String joinedCommand = String.join(" ", command);
LOGGER.debug("Executing shell command: `{}`", joinedCommand);
try {
ProcessResult result;
result = new ProcessExecutor()
.command(command)
.readOutput(true)
.exitValueNormal()
.execute();
return result.outputUTF8().trim();
} catch (IOException | InterruptedException | TimeoutException | InvalidExitValueException e) {
throw new ShellCommandException("Exception when executing " + joinedCommand, e);
}
}
开发者ID:testcontainers,项目名称:testcontainers-java,代码行数:25,代码来源:CommandLine.java
示例5: kill
import org.zeroturnaround.exec.InvalidExitValueException; //导入依赖的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;
}
}
开发者ID:zeroturnaround,项目名称:zt-process-killer,代码行数:24,代码来源:UnixProcess.java
示例6: isNoSuchProcess
import org.zeroturnaround.exec.InvalidExitValueException; //导入依赖的package包/类
@Override
protected boolean isNoSuchProcess(InvalidExitValueException e) {
return e.getExitValue() == EXIT_CODE_NO_SUCH_PROCESS;
}
开发者ID:zeroturnaround,项目名称:zt-process-killer,代码行数:5,代码来源:SolarisProcess.java
示例7: testJavaVersionExitValueCheck
import org.zeroturnaround.exec.InvalidExitValueException; //导入依赖的package包/类
@Test(expected=InvalidExitValueException.class)
public void testJavaVersionExitValueCheck() throws Exception {
new ProcessExecutor().command("java", "-version").exitValues(3).execute();
}
开发者ID:zeroturnaround,项目名称:zt-exec,代码行数:5,代码来源:ProcessExecutorExitValueTest.java
示例8: testJavaVersionExitValueCheckTimeout
import org.zeroturnaround.exec.InvalidExitValueException; //导入依赖的package包/类
@Test(expected=InvalidExitValueException.class)
public void testJavaVersionExitValueCheckTimeout() throws Exception {
new ProcessExecutor().command("java", "-version").exitValues(3).timeout(60, TimeUnit.SECONDS).execute();
}
开发者ID:zeroturnaround,项目名称:zt-exec,代码行数:5,代码来源:ProcessExecutorExitValueTest.java
示例9: testCustomExitValueInvalid
import org.zeroturnaround.exec.InvalidExitValueException; //导入依赖的package包/类
@Test(expected=InvalidExitValueException.class)
public void testCustomExitValueInvalid() throws Exception {
new ProcessExecutor(exitLikeABoss(17)).exitValues(15).execute();
}
开发者ID:zeroturnaround,项目名称:zt-exec,代码行数:5,代码来源:ProcessExecutorExitValueTest.java
示例10: isNoSuchProcess
import org.zeroturnaround.exec.InvalidExitValueException; //导入依赖的package包/类
/**
* @param e process exited with an error code.
* @return <code>true</code> if this exception indicates that the process was not found (any more).
*/
protected boolean isNoSuchProcess(InvalidExitValueException e) {
return e.getExitValue() == EXIT_CODE_NO_SUCH_PROCESS;
}
开发者ID:zeroturnaround,项目名称:zt-process-killer,代码行数:8,代码来源:UnixProcess.java
注:本文中的org.zeroturnaround.exec.InvalidExitValueException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论