1
發送OS X終端命令我想看看如果iPhone是在OS X tehtered模式,我無法發送使用此代碼的終端命令:無法通過Java
String [] cmdArray = new String[1];
cmdArray[0] = "/usr/sbin/networksetup -getinfo \"iPhone USB\"";
SendCommandForResponse(cmdArray);
...
static String SendCommandForResponse(String[] commandArray) throws IOException {
InputStream processOutput;
BufferedReader reader = null;
String line = " ", output = " ";
Runtime rt = Runtime.getRuntime();
Process p = rt.exec(commandArray);
processOutput = p.getInputStream();
reader = new BufferedReader(new InputStreamReader(processOutput));
while ((line = reader.readLine()) != null) {
System.out.println(line);
output += line + "\n";
}
return output;
}
當這個代碼是跑了,我收到此錯誤:
IOException: java.io.IOException: Cannot run program "/usr/sbin/networksetup -getinfo "iPhone USB"": error=2, No such file or directory
我能夠通過TE成功運行此命令rminal,但是在NetBeans內部運行時會發生異常。我究竟做錯了什麼?我是新來的Java在OS X
工作。非常感謝! – Ducksauce88