1

I want to disconnect my computer from the internet, and the best way that I can think of, is running the ipconfig/release from the cmd. To do so, I did

 Process result = Runtime.getRuntime().exec("ipconfig/release");

This throws an error however,

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

Which I am not sure what means.

Any ideads what I'm doing wrong? Any better alternatives to disconnect from the router?

StupidQuestions
  • 347
  • 2
  • 10
  • 1
    Shouldn't it be `ipconfig /release` (note the space), also, generally speaking, it's usually easier to use `ProcessBuilder` and separate each command and parameter as it's own argument `new ProcessBuilder("ipconfig", "/release");` – MadProgrammer Mar 25 '15 at 05:32
  • @MadProgrammer If you are on Windows, try `ipconfig/release"` from the command line – Scary Wombat Mar 25 '15 at 05:33
  • 2
    The Windows command line has bug-compatible behavior that splits tokens on slashes. I doubt that the Windows equivalent of `exec` does the same. – chrylis -cautiouslyoptimistic- Mar 25 '15 at 05:35
  • It was the space that did it, thanks. It's weird though, it works without the space if I type it directly in cmd. – StupidQuestions Mar 25 '15 at 05:39

2 Answers2

0

It works with a space

Process result = Runtime.getRuntime().exec("ipconfig /release");
StupidQuestions
  • 347
  • 2
  • 10
  • You can try with this also C:/Windows/System32/ipconfig.exe /release,, giving complete path of the ipconfig – Kick Mar 25 '15 at 05:43
0

Assuming that ipconfig.exe is in the PATH, then Runtime.exec is capable of finding it, if it is not, you will need to supply the fully qualified path to it.

kk1992
  • 153
  • 1
  • 3