I have a program that uses ProcessBuilder
in order to run a different program.
My code looks like this:
public class runMultiClient {
public static void main(String[] args){
if (args[0].matches("-f")){
String dir = System.getProperty("user.dir");
String path = dir + "\\" + args[1];
FileReader fr;
try {
fr = new FileReader(path);
BufferedReader bf = new BufferedReader(fr);
String line = "";
Process PR = null;
while ((line = bf.readLine()) != null){
String[] tk = line.split(" ");
String[] cmd = {"javaw", "-jar", "ntripClient.jar", "-a", tk[0], "-p", tk[1],
"-u", tk[2], "-pw", tk[3], "-m", tk[4], "-t", tk[5], "-s", tk[6]};
ProcessBuilder pb = new ProcessBuilder(cmd);
PR = pb.start();
}
PR.waitFor();
}
catch (FileNotFoundException ex) {ex.printStackTrace();}
catch (IOException ex) {ex.printStackTrace();}
catch (InterruptedException ex) {ex.printStackTrace();}
}
}}
I run this program from cmd. It excepts a name for the initiation file which contains data in each row. Based on this file it suppose create several processes.
However, it does not run smoothly. Right now i have 2 rows in the initiation file, meaning two processes should have been started. What it actually did is start the first process, then stopped it and started the second one instead. Another problem is that i do not know how to kill the process, it seems to be running in the background and does not appear in the task manager. Crtl+C and Ctrl+Break does not work.
The main goal is to run several processes in the same time and being able to break the process when needed. What am i missing? how do i fix this issue? Any help would be appreciated.
Without being able to reproduce this (for lack of the subject JAR), one of three things is probably happening:
Some things to try: