1

I Tried the following code , no exception is raised but the opendhcpserver program does not stop, even tried debugging but still no clue. Using this command to run the program

Process p= new Precess();
p = Runtime.getRuntime().exec("cmd.exe /C C:\\OpenDHCPServer\\OpenDHCPServer.exe -v");

using this to close

p.destroy();
Harry Joy
  • 58,650
  • 30
  • 162
  • 207
cornercoder
  • 276
  • 1
  • 4
  • 15
  • 1
    Why not just `exec("C:\\OpenDHCPServer\\OpenDHCPServer.exe -v")`? – Daniel Lubarov Mar 05 '12 at 04:57
  • Please don't use `\\ ` (or `\ `) in your command-line paths on Windows. It hasn't been required for some time now. Windows has supported `/` in filesystem paths since the days of XP. – aroth Mar 05 '12 at 05:24
  • You would like to see this http://stackoverflow.com/questions/801609/java-processbuilder-process-destroy-not-killing-child-processes-in-winxp – gt5050 Mar 05 '12 at 05:25
  • @daniel that still wont solve my problem of closing it – cornercoder Mar 05 '12 at 05:50

1 Answers1

2

First thing Process is abstract class you cant instantiate it,

Use Separate methods to start & stop an application, so that when you execute start method it will start the application & when you execute stop method it will stop application. Then it will work as you think.

Vinesh
  • 933
  • 2
  • 7
  • 22
  • I have put the two commands on diffrent functions but still now i use Process p; Start Button p = Runtime.getRuntime().exec("C:\\OpenDHCPServer\\OpenDHCPServer.exe -v"); Stop button p.destroy(); but still the process started by windowns for OpenDHCPServer still remains – cornercoder Mar 05 '12 at 05:53
  • no exceptions are thrown ...... can there be a way to provide teh instance running the process a Ctrl+c to stop it??? – cornercoder Mar 09 '12 at 05:50