I agree with Ulf. If you ignore the hint, you catch the exit code with $? (at least bash works that way):
But returncode not 0 indicates an error, and the wrong approach to return a correct result. If the program fails, you can't recognize this anymore, and if you use it in a script, everybody is confused.
The right way is indeed to use System.out.println (result); and read that value, but of course without the detour of writing to a file: