第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用Unix命令在Java中打印Mac的序列號

使用Unix命令在Java中打印Mac的序列號

猛跑小豬 2019-12-06 10:48:56
我正在嘗試在Java程序中打印Mac的[編輯:Apple計算機]序列號。我熟悉Unix命令ioreg -l | awk '/IOPlatformSerialNumber/ { print $4;}'在終端中完成此任務。當我嘗試String command = "ioreg -l | awk '/IOPlatformSerialNumber/ { print $4; }'"Runtime terminal = Runtime.getRuntime(); String input = new BufferedReader(    new InputStreamReader(        terminal.exec(commands).getInputStream())).readLine();System.out.println(new BufferedReader(    new InputStreamReader(        terminal.exec(command, args).getInputStream())).readLine());我的序列號未打印。而是打?。?lt;+-o Root class IORegistryEntry, id 0x100000100, retain 10>  我認為問題是這terminal.exec()并不意味著要使用整個命令字符串。Java中是否有類似于shell = Truepython中的參數(shù)的東西Popen(command, stdout=PIPE, shell=True),可以讓我傳遞整個命令字符串?
查看完整描述

3 回答

?
LEATH

TA貢獻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();

另外,您當然可以將Shell作為進程運行


查看完整回答
反對 回復 2019-12-06
?
慕蓋茨4494581

TA貢獻1850條經(jīng)驗 獲得超11個贊

要通過Java獲取MAC地址,可以使用java.net.NetworkInterface:


NetworkInterface.getByName("xxx").getHardwareAddress()

如果您不知道網(wǎng)絡接口的名稱(我在Linux上假定為'eth0'),則甚至可以使用遍歷所有網(wǎng)絡接口NetworkInterface.getNetworkInterfaces()。


查看完整回答
反對 回復 2019-12-06
  • 3 回答
  • 0 關注
  • 422 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號