"The output... is not correct" doesn't help anyone to diagnose your issue. You should definitely give the output you expected, and the output you saw from Java. Assuming that your program is small, you should post the source code of that too (since this is about the compilation process after all).
By the way, what happens when you navigate to the working direction of the Java program, find the function
executable it generating and invoke that yourself from the command line? Is the output correct now? The answer to this will let you know whether the problem is in the compilation step or the execution step.
If it's execution, I would hazard a guess at things like the environment (envvars, PATH, etc.) but without more information it's hard to tell.
Also, as with all question that involve Process
es, take a look at these common pitfalls. It looks like you're making at least one of them (the common one of not consuming output) which might lead to your program working on trivial C++ code but deadlocking on a larger codebase.
You're also not checking the output (either the return value or the stdout/stderr streams) of the compilation step at all, so you have no idea whether the compilation was successful - and if not, what (useful) error messages you got from the compiler.