3 回答

TA貢獻(xiàn)1936條經(jīng)驗 獲得超7個贊
Runtime.exec(..)不支持管道,因為它們是Shell的功能。相反,您必須自己模擬管道,例如
String ioreg = toString(Runtime.exec("ioreg -l ").getInputStream());
Process awk = Runtime.exec("awk '/IOPlatformSerialNumber/ { print $4;}'");
write(awk.getOutputStream(), ioreg);
String input = new BufferedReader(new InputStreamReader(awk.getInputStream())).readLine();
另外,您當(dāng)然可以將Shell作為進(jìn)程運(yùn)行

TA貢獻(xiàn)1850條經(jīng)驗 獲得超11個贊
要通過Java獲取MAC地址,可以使用java.net.NetworkInterface:
NetworkInterface.getByName("xxx").getHardwareAddress()
如果您不知道網(wǎng)絡(luò)接口的名稱(我在Linux上假定為'eth0'),則甚至可以使用遍歷所有網(wǎng)絡(luò)接口NetworkInterface.getNetworkInterfaces()。
添加回答
舉報