capture echoed text from shell script

I have a korn shell script that echoes a word to the terminal. From within my java application, is there any way to call this script and capture the text that it echoes?
[176 byte] By [PatrickFinnigana] at [2007-11-27 8:12:09]
# 1

Related, and simpler, question -

Q: When I execute the following code, the shell process executed here hangs. Also, the file /tmp/secLevel is never created (and never modified if it already exists).

Runtime.getRuntime().exec("/bin/ksh -c /usr/local/bin/getSecLevel > /tmp/secLevel");

Here are the contents of /usr/local/bin/getSecLevel:

#!/bin/ksh

level=`replace me later`

echo $level

exit

PatrickFinnigana at 2007-7-12 19:56:29 > top of Java-index,Core,Core APIs...
# 2
Use the Process class ( returned by Runtime.exec ) to read the error stream and the input stream continuosly once the exec method is called. Not doing that will cause you program to block.You can probably define 2 threads to continuosly read and clear the streams
harsha_ava at 2007-7-12 19:56:29 > top of Java-index,Core,Core APIs...
# 3

Process proc = Runtime.getRuntime().exec("command");

InputStream in = proc.getInputStream();

proc.waitFor();

byte[] result = new byte[in.available()];

in.read(result);

in.close();

System.out.println(new String(result));

it works only if no errors occurs.

To catch Errors use getErrorStream() method.

good luck

pbulgarellia at 2007-7-12 19:56:29 > top of Java-index,Core,Core APIs...
# 4

It also works only if the OS inter-process (pipe) buffer doesn't fill up before the command exits. Typically this is a fairly small buffer, so the chances are high that it will.

Better is to use something approaching this technique, but to read the stream using a separate thread. You can re-use your thread to separately read the error stream too.

dannyyatesa at 2007-7-12 19:56:29 > top of Java-index,Core,Core APIs...