我想斷開我的電腦與互聯網的連接,而我能想到的最佳方式是從cmd運行ipconfig/release。要做到這一點,我做了Java Runtime.getRuntime()。exec(「ipconfig/release」);返回錯誤?
Process result = Runtime.getRuntime().exec("ipconfig/release");
這不過拋出一個錯誤,
java.io.IOException: Cannot run program "ipconfig/release": CreateProcess error=
2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at threadio.run(checkmac.java:141)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find th
e file specified
這我不知道是什麼意思。
任何想法我做錯了什麼?任何更好的選擇從路由器斷開?
不應該是'ipconfig/release'(注意空間),一般來說,通常使用'ProcessBuilder'並將每個命令和參數分隔爲自己的參數'new ProcessBuilder(「ipconfig」, 「/ release」);' – MadProgrammer 2015-03-25 05:32:38
@MadProgrammer如果你在Windows上,請從命令行嘗試'ipconfig/release' – 2015-03-25 05:33:44
Windows命令行具有錯誤兼容的行爲,可以在斜槓上分割令牌。 'exec'也是一樣的, – chrylis 2015-03-25 05:35:31