exec() starts new process after my program finishes
807580Jan 21 2010 — edited Jan 21 2010Hi all,
I have a problem. I must create a subprocess and connect to it with socket.
My process:
0. String command_to_exec_subprocess="java -cp"+cp+" mypackage.MyMainClass "+args;
1. Runtime.getRuntime().exec(command_to_exec_subprocess);
2. socket.connect(new InetSocketAddress("localhost",25000), 3000);
My subprocess:
1. ServerSocket server=new ServerSocket(25000);
JFrame jf=new JFrame();
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setVisible(true);
2. Socket client=server.accept();
I use: Windows 7
JVM: 1.6
Problem is that frame popsup after my process finished, socket can never connect to server socket. As far as I know this means that Runtime waits with starting subprocess till my main process ends... Does any one know how to make the process execute just after I use exec command?? I tryed to use ProcessBuilder but when I use it it doesnt even start the subprocess... When i run the command from cmd on windows7 it runs with no problem.
Thx.