I am trying to run a executable file generated by c in Java. Originally, I can run it on terminal with
./bin/svm-train -s 0 -t 0 -d 3 -g 0.0 -r 0.0 -n 0.5 -m 40.0 -c 1.0 -e 0.001 -p 0.1 ./data/trainfile ./model/update.model
This command on terminal works well and it will take a few seconds to generate a file 'update.model' as indicated in the code.
But when I try to put this process in Java with the following code, the program ends without generating 'update.model'
String[] cmdUpdateTrain = new String[]{"/bin/bash", "-c", "./bin/svm-train -s 0 -t 0 -d 3 -g 0.0 -r 0.0 -n 0.5 -m 40.0 -c 1.0 -e 0.001 -p 0.1 ./data/trainfile ./model/update.model"};
Runtime.getRuntime().exec(cmdUpdateTrain);
If I try with the following code with Java, it works fine the model can also be generated.
String[] cmdUpdateTrain = new String[]{"/bin/bash", "-c", "./bin/svm-train ./data/trainfile ./model/update.model"};
Runtime.getRuntime().exec(cmdUpdateTrain);
So I think it may be the problem of handling parameter for ./bin/svm-train
.
I have found why it happens. It is because the program ends before the execution of ./bin/svm-train
stops.
And the following code fix this problem.
try{
String[] cmdUpdateTrain = new String[]{"/bin/bash", "-c", "./bin/svm-train -s 0 -t 0 -d 3 -g 0.0 -r 0.0 -n 0.5 -m 40.0 -c 1.0 -e 0.001 -p 0.1 ./data/trainfile ./model/update.model"};
Process psTrain = Runtime.getRuntime().exec(cmdUpdateTrain);
psTrain.waitFor();
}catch(InterruptedException interupt){
}