Reputation: 869
I am trying to run an exe file while setting some parameters for it like this:
myExePath -ini myIniPath -x myConfigFilePath
When I run it from the command line it works perfectly. But when I try running it from my Java code the process starts but after a while is not responding anymore so I have to forcibly close it. I am using this Java code:
List<String> parameters = new ArrayList<String>();
parameters.add(myexePath);
parameters.add("-ini ");
parameters.add(myIniPath);
parameters.add("-x ");
parameters.add(myConfigPath
ProcessBuilder builder = new ProcessBuilder(parameters);
Process process = builder.start();
try {
process.waitFor();
} catch (InterruptedException e) {
System.err.println("Process was interrupted");
}
Any ideas what I am doing wrong?
Upvotes: 0
Views: 1821
Reputation: 3815
I guess you should first get a reference to the Runtime
.
You could do this
Runtime.getRuntime().exec(parameters.toString());
Your string from the parameters list may need a bit formatting.
Upvotes: 0
Reputation: 11607
Does the exe use stdout, stderr, stdin? You should always read from them or close them. Depending on the implementation and buffer size not reading from them could lead to blocking.
Upvotes: 1
Reputation: 3191
I'm not sure if it helps, but why you use spaces?
e.g.: parameters.add("-x ");
You don't need them.
What you can also try is to put all your parameters in an array and use another constructor of ProcessBuilder which takes an array as argument.
Upvotes: 0