I don't quite understand your question In your code Java code, it doesn't seem to print anything. If you invoke test.sh, of course you won't see anything.
If let's say you have a Hello World program, then you run it from your script, I'm pretty sure you can see the Hello World message in your shell.
SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4
My Blog
Sri Anand
Ranch Hand
Joined: Mar 06, 2005
Posts: 392
posted
0
you can save the property in a file and retrieve either from java or shell. if this is not too much for what you are trying to achieve
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35253
7
posted
0
While it's possible to use System.exit to pass a value to the shell, that's meant for status codes. If the program runs to completion without error, then it should return a 0 to the shell.
The standard approach would be to print the value to standard out. What kind of shell are you using?
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:
...or you can throw whatever you want to STDOUT (System.out, you know, right?) and from the bash side use "while read variable" to get the output and work on it:
Example (not java related): $ dmesg | while read line; do echo $line; done
replace dmesg for the java command to run your application and enjoy!