[問題] 在app中執行ifconfig
android和linux新手,請教各位前輩,希望問題描述得正確:
我在板子上灌Android系統,用rndis module讓板子與手機能以USB相連。
但是每次重插USB之後ip都會消失,要再重新設定一次ip,
也就是要在minicom中手動打:ifconfig usb0 x.x.x.x來對板子設定ip。
所以我在app當中寫了一段程式碼來自動設ip,當我開這個app時就會先幫我把ip設好,
然後執行其他的功能。
找了一些資料後寫出下面的程式碼,可以達到我的需要:
public void ifconfigUsb0IP(String strIP){
Process process = null;
DataOutputStream os = null;
try {
process = Runtime.getRuntime().exec("su");
os = new DataOutputStream(process.getOutputStream());
os.writeBytes("ifconfig usb0 "+strIP+"\n");
os.flush();
} catch (Exception e) {
e.getMessage();
}
}
可是我想讓這個app不要使用到root權限。
所以我去版子的/system/bin裡面把ifconfig檔權限設為system system rwxrwxrwx
然後改寫程式碼為
public void ifconfigUsb0IP(String strIP){
Process process = null;
DataOutputStream os = null;
try {
process = Runtime.getRuntime().exec("ifconfig usb0 "+strIP);
} catch (Exception e) {
e.getMessage();
}
}
可是不work。
我試過幾種方法改寫都不成功,不曉得是一開始改ifconfig權限的想法就錯了,
還是單純是在Runtime.getRuntime().exec("ifconfig usb0 "+strIP);語法上的錯誤呢?
謝謝回覆:)
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.61.240.28
→
12/04 19:43, , 1F
12/04 19:43, 1F
→
12/04 19:43, , 2F
12/04 19:43, 2F
→
12/04 19:45, , 3F
12/04 19:45, 3F
→
12/05 09:14, , 4F
12/05 09:14, 4F
→
12/05 09:14, , 5F
12/05 09:14, 5F
→
12/05 15:13, , 6F
12/05 15:13, 6F
→
12/05 15:14, , 7F
12/05 15:14, 7F
→
12/05 15:15, , 8F
12/05 15:15, 8F
→
12/10 02:46, , 9F
12/10 02:46, 9F