Java Runtime.getRuntime().exec(“ipconfig/release”);返回错误?
我想断开我的计算机与internet的连接,我能想到的最好的方法是从cmd运行ipconfig/release。为了做到这一点,我做到了Java Runtime.getRuntime().exec(“ipconfig/release”);返回错误?,java,runtime,ipconfig,Java,Runtime,Ipconfig,我想断开我的计算机与internet的连接,我能想到的最好的方法是从cmd运行ipconfig/release。为了做到这一点,我做到了 Process result = Runtime.getRuntime().exec("ipconfig/release"); 但这会抛出一个错误 java.io.IOException: Cannot run program "ipconfig/release": CreateProcess error= 2, The system cannot fin
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
我不知道这是什么意思
你知道我做错了什么吗?有没有更好的办法来断开与路由器的连接?它使用的是一个空间
Process result = Runtime.getRuntime().exec("ipconfig /release");
假设ipconfig.exe在路径中,那么Runtime.exec能够找到它,如果它不在,您将需要为它提供完全限定的路径。它不应该是
ipconfig/release
(注意空格),一般来说,通常更容易使用ProcessBuilder
,并将每个命令和参数作为自己的参数newprocessbuilder(“ipconfig”、“/release”)
@MadProgrammer如果您在Windows上,请尝试ipconfig/release“
从命令行Windows命令行具有与错误兼容的行为,可以在斜杠上拆分令牌。我怀疑Windows中相当于exec
的版本是否也能做到这一点。谢谢,正是空间做到了这一点。不过这很奇怪,如果我直接在cmd中键入它,它就可以在没有空格的情况下工作。您也可以尝试使用它C:/Windows/System32/ipconfig.exe/release,给出ipconfig的完整路径