몇 가지 함수를 사용하여 클래스를 만드는 중, 이러한 함수 중 하나에 문제가있어 ProcessBuilder를 사용하여 명령을 보내고 출력을 문자열로 사용하여 셸 명령으로 사용합니다. 내가 그것을 사용할 때 InputStreamReader에 잘못된 파일 번호가있는 IOException을 catch하고 "ERROR !!!"를 반환합니다. 여기 내 코드는 다음 InputStreamReader에서 IOException
public String builder(String str) {
startTimer(); // A method that gets the current time as int
String[] array = str.split(" " , 2);
String cmd = array[0] + " " + array[1];
System.out.println("\nexecuting: " + cmd + "----");
String AllText = "";
try {
String anyString;
//Process process = new ProcessBuilder("sh","-c","\"",cmd,"\"").start();
Process process = new ProcessBuilder(array).start();
BufferedReader OUT = new BufferedReader(new InputStreamReader(process.getInputStream())); // Here is My error
BufferedReader ERR = new BufferedReader(new InputStreamReader(process.getErrorStream()));
try {
for (int x = endTimer()/* a method which subtracts the startTimer() from current time to get the time passed */ ; endTimer()<= 5000 ; x++){
process.waitFor();
}process.destroy();
} catch (InterruptedException ex) {
ex.printStackTrace();
}
while ((anyString = ERR.readLine()) != null) {
AllText = AllText + "\n" + anyString;
}
while ((anyString = OUT.readLine()) != null) {
AllText = AllText + "\n" + anyString;
while ((anyString = ERR.readLine()) != null) {
AllText = AllText + "\n" + anyString;
}
}
return AllText;
} catch (Exception ex) {
ex.printStackTrace();
return "ERROR!!!";
}
이 때 스택 추적은 ... "LS"BTW, "LS/SDCARD /"이 댓글에 대해 아무것도 알 필요가 있다면 ... 내가 명령을 사용하고있다 버튼을 누르십시오 :
12-03 18:55:36.475: W/System.err(17973): java.io.IOException: read failed: EBADF (Bad file number)
12-03 18:55:36.507: W/System.err(17973): at libcore.io.IoBridge.read(IoBridge.java:442)
12-03 18:55:36.507: W/System.err(17973): at java.io.FileInputStream.read(FileInputStream.java:179)
12-03 18:55:36.507: W/System.err(17973): at java.io.InputStreamReader.read(InputStreamReader.java:244)
12-03 18:55:36.507: W/System.err(17973): at java.io.BufferedReader.fillBuf(BufferedReader.java:130)
12-03 18:55:36.507: W/System.err(17973): at java.io.BufferedReader.readLine(BufferedReader.java:354)
12-03 18:55:36.507: W/System.err(17973): at com.example.activity.over.other.Shells.builder(Shells.java:542)
12-03 18:55:36.507: W/System.err(17973): at com.example.activity.over.other.MainActivity$2.onClick(MainActivity.java:91)
12-03 18:55:36.514: W/System.err(17973): at android.view.View.performClick(View.java:4202)
12-03 18:55:36.514: W/System.err(17973): at android.view.View$PerformClick.run(View.java:17340)
12-03 18:55:36.514: W/System.err(17973): at android.os.Handler.handleCallback(Handler.java:725)
12-03 18:55:36.514: W/System.err(17973): at android.os.Handler.dispatchMessage(Handler.java:92)
12-03 18:55:36.514: W/System.err(17973): at android.os.Looper.loop(Looper.java:137)
12-03 18:55:36.514: W/System.err(17973): at android.app.ActivityThread.main(ActivityThread.java:5039)
12-03 18:55:36.514: W/System.err(17973): at java.lang.reflect.Method.invokeNative(Native Method)
12-03 18:55:36.522: W/System.err(17973): at java.lang.reflect.Method.invoke(Method.java:511)
12-03 18:55:36.522: W/System.err(17973): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-03 18:55:36.522: W/System.err(17973): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-03 18:55:36.522: W/System.err(17973): at dalvik.system.NativeStart.main(Native Method)
12-03 18:55:36.522: W/System.err(17973): Caused by: libcore.io.ErrnoException: read failed: EBADF (Bad file number)
12-03 18:55:36.530: W/System.err(17973): at libcore.io.Posix.readBytes(Native Method)
12-03 18:55:36.530: W/System.err(17973): at libcore.io.Posix.read(Posix.java:123)
12-03 18:55:36.530: W/System.err(17973): at libcore.io.BlockGuardOs.read(BlockGuardOs.java:149)
12-03 18:55:36.530: W/System.err(17973): at libcore.io.IoBridge.read(IoBridge.java:432)
12-03 18:55:36.530: W/System.err(17973): ... 17 more
스택 추적 후 – njzk2
쉘을 구현하거나 sdcard 파일 목록을 읽는 것이 목표입니까? 쉘 루트를 사용하여 목표를 달성 할 수있는보다 명확한 방법이 있기 때문에 단지 궁금합니다. – Grambot
@ njzk2 게시 됨, 체크 아웃 ... –