Reputation: 966
I want to run a C++ program from Java in Linux
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("/home/user/myProgram inputFilePath secondArgument");
int exitVal = pr.waitFor();
If I run the same command from a terminal everything works fine, the problem is when I run it from Java. I am getting exit code 139. The program gets executed but something fails while executing. Actually if I do not enter the inputFilepath
the program is executed just fine and I can catch the message over the stdout about the "missing input file".
Any idea?
SOLUTION: After some trial and error I found the problem. Apparently a "\n" was needed at the end of the parameters, probably used as flag by the C++ program I was running. There was for sure a segmentation fault while parsing the arguments.
Upvotes: 1
Views: 3933
Reputation: 25380
139 is the exit code that you'd see if the C++ program crashed with a segmentation fault. This would indicate a memory access bug within the C++ program. See Are there any standard exit status codes in Linux?.
Alternately, the program could have exited with exit code 139 for reasons of its own. Without knowing what the program is, it's not really possible to be more specific.
Upvotes: 2
Reputation: 244
Did you check what this command returns in your Linux console? Try to run "/home/user/myProgram inputFilePath secondArgument; echo $?". 139 on exit means the command returned 139 and it is not a problem of your Java code.
Upvotes: 0