[英]Android Nougat, Runtime.exec won't work
I'm trying to create a terminal emulator. 我正在尝试创建一个终端模拟器。 My code is
我的代码是
ProcessBuilder builder = new ProcessBuilder("/system/bin/sh");
builder.redirectErrorStream(true);
builder.directory(f);
p = builder.start();
stdOut = p.getInputStream();
stdIn = p.getOutputStream();
stdIn.write(("ls\n").getBytes());
stdIn.write(("echo EOF\n").getBytes());
while(true) {
int n;
try {
n = stdOut.read();
} catch (Exception | Error e) {
return;
}
if(n == -1) continue;
char c = (char) n;
if(c == '\n') {
if(line.equals("EOF")) break;
else {
if(write) outputable.onOutput(line);
outputMsg[0] = outputMsg[0] + "\n" + line;
line = "";
}
} else {
line = line + c;
}
}
This code works on Android 6.0, 5.0, 4.0, 3.0... It doesn't work on Nougat (7.0). 这段代码可在Android 6.0、5.0、4.0、3.0 ...上运行,而在Nougat(7.0)上无法运行。 No errors, no exceptions, nothing.
没有错误,没有例外,什么都没有。 It just hangs on this line:
它只是挂在这条线上:
n = stdOut.read();
InputStream .read() should hang only when there's nothing available in the stream. InputStream .read()仅在流中没有可用时才挂起。 Does someone know the solution?
有人知道解决方案吗?
I solved my problem using Chainfire's library libsuperuser . 我使用Chainfire的库libsuperuser解决了我的问题。 Not a solution, but at least a workaround.
不是解决方案,但至少是解决方法。 And, one could also investigate the code, looking for a decisive difference, if he wants.
而且,如果他愿意,还可以调查代码,寻找决定性的差异。
That's not my case, libsuperuser works like a charm. 那不是我的情况,libsuperuser就像一个魅力。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.