2011-01-06 2 views
6

그래서 logcat 메시지 dmesg를 켜고 표시 할 수있는 응용 프로그램을 작성하고 'ls'와 같은 명령을 실행할 수 있기를 원합니다. cat ''echo ''cd '.Android Runtime.getRuntime(). 디렉토리를 탐색하는 exec()

다음 작업을 수행 할 경우

nativeProc = Runtime.getRuntime().exec("ls\n"); 
     BufferedWriter out = new BufferedWriter(new OutputStreamWriter(nativeProc.getOutputStream())); 
     BufferedReader in = new BufferedReader(new InputStreamReader(nativeProc.getInputStream())); 
     String line = null; 

     while ((line = in.readLine()) != null) { 
      full = full + "\n" + line; 
     } 

나는 텍스트보기로 텍스트 "전체"를 넣고 루트 디렉토리를 볼 수 있습니다.

그러나 그게 내가 할 수있는 전부입니다. 디렉토리를 찾고 그것을 변경하려고 할 때 문제가 발생한다고 가정 해 보겠습니다.

내가 이렇게 그래서 경우 :

nativeProc = Runtime.getRuntime().exec("ls\n"); 
     BufferedWriter out = new BufferedWriter(new OutputStreamWriter(nativeProc.getOutputStream())); 
     BufferedReader in = new BufferedReader(new InputStreamReader(nativeProc.getInputStream())); 
     String line = null; 

     while ((line = in.readLine()) != null) { 
      full = full + "\n" + line; 
     } 
     /* Code here to confirm the existing of a directory*/ 


     nativeProc = Runtime.getRuntime().exec("cd tmp\n"); 
     BufferedReader in2 = new BufferedReader(new InputStreamReader(nativeProc.getInputStream())); 
     line = null; 
     String test = "\nStart1:\n"; 
     while ((line = in2.readLine()) != null) { 
      test = test + "\n" + line; 
     } 

내가 "풀"과 "텍스트"

모든 아이디어를 모두 아무것도 얻을 수 없다?

답변

4

당신은 폴더를 나열해야하는 제공 경로와 LS를 실행할 수 있습니다

Runtime.getRuntime().exec(new String[] { "ls", "\\tmp"}); 
2

현재 작업 디렉토리는 현재 프로세스와 연관되어 있습니다. 당신이 exec ("cd tmp") 할 때 프로세스를 생성하고 그 디렉토리를 "tmp"로 변경하면 프로세스가 종료됩니다. 상위 프로세스의 작업 디렉토리는 변경되지 않습니다.

자세한 내용은 changing the current working directory in Java을 참조하십시오.

1

이 파일에 파일 및 다른 모든 구현이 있는지 확인하고 sdcard에 추가하고 getRuntimr.exec()를 사용하여 java에서 쉘 파일을 시작하는 방법에 대해 설명합니다. 매개 변수를 전달할 수도 있습니다 .

관련 문제