안녕하세요 ~
예를 들어
adb shell 로 핸드폰 안으로 들어 가서 (핸드폰은 루팅이 되어 잇어요... 상관 없을 지 모르지만 혹시나 해서요 ,..)
String permission = "chmod 777 /data/loca/output.txt\n";
String read = "cat output.txt\n";
이 두개의 명령어를
DataOutputStream os = new DataOutputStream(process.getOutputStream());
os.writeBytes(permission);
os.flush();
os.writeBytes( read );
os.flush();
os.close();
이런식으로 액티 비티 단에서 컨솔로 명령어를 넘겨 준다고 하면...
output.txt의 내용들을 컨솔 내에서 출력 해 줄 텐데요.. 만약 그 내용들이 밑에와 같다고 하면
----------------------------------------------
HELLO, ANDROID!
----------------------------------------------
이 문장을 그래도 안드로이드 액티비티 내의 textView에서 받아서 보여 줄 수 있을 까요?ㅠ_ㅜ
위의 것은 예시 입니다...
꼭 알려 주세요 감사합니다!!
답글 주셔서 감사합니다!
일단 말씀 해 주신 내용으로 코드를 짜 보았는데요...
public void start_onClick(View v) {
// TODO Auto-generated method stub
try {
process = Runtime.getRuntime().exec("chmod 777 /data/local/output.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
TextView show = (TextView)findViewById(R.id.content);
String str = new String();
str = br.readLine();
show.setText(str);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
디버그로 확인을 해 보니... str 값에 Null 값이 들어 옵니다... 아무래도 br 에서 아무 것도 읽어 들이지 못하는것 같아요 ㅠ-ㅜ
보시는 것과 같이.. 폰으로 들어가서 chmod 777 /data/local/output.txt 명령어를 치게 되면 ..
chmod 777 /data/local/output.txt 이렇게 응답이 나옵니다...
저는 이런식으로 이 응답들을 textView로 보여 주고 싶은데...
그럼 BufferedRead 의 br에 이 응답이 안들어 가는 건가요??
ㅠ_ㅜ
답변 부탁드려요 !
감사합니다!




전에 이런식으로 처리했던 기억은 있군요..
BufferedReader에서 읽어와서 보여주면 될듯합니다.
Process process;
Runtime runtime = Runtime.getRuntime();
String cmd = "명령어";
process = runtime.exec(cmd);
BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));