2012-08-29 43 views
0

假設這樣的:植根手機上執行的進程與參數無效

Runtime runtime = Runtime.getRuntime(); 
Process process = runtime.exec(SU); 
DataOutputStream processStream = new DataOutputStream(process.getOutputStream()); 
processStream.writeChars("cat /qwerty"); 
processStream.writeChars(EXIT); 
processStream.flush(); 

int status = process.waitFor(); 

Log.d("EXIT STATUS", String.valueOf(status)); 

process.waitFor();導致當前線程等待永遠。我想問題在於那個無效的命令(我故意這麼做)。但我該如何處理這種情況呢?

Busybox的1.17.1

回答

1

當您發送使用writeChars命令,它們都在外殼會在同一行,從來沒有被實際執行,我認爲。你需要放入換行符來執行shell。試試這個:

Runtime runtime = Runtime.getRuntime(); 
Process process = runtime.exec(SU); 
DataOutputStream processStream = new DataOutputStream(process.getOutputStream()); 
processStream.writeChars("cat /qwerty\n"); 
processStream.writeChars("exit \n"); 
processStream.flush(); 

int status = process.waitFor(); 

Log.d("EXIT STATUS", String.valueOf(status)); 
+0

謝謝,我的錯。 –