I am trying to get bash data into a variable. The problem is that this is so darn randomly. The command is executed every time, I see that the application X is starting up. However, my processor may be too fast or slow to issue the echo command and start the buffered read to the input stream.
How can I make this work? I need to somehow issue a command inside a buffered reader.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class test1 {
public static void main() {
try {
Process proc = Runtime.getRuntime().exec("echo Gosh, I sure hope this comes back to java");
BufferedReader read = new BufferedReader(new InputStreamReader(proc
.getInputStream()));
while (read.ready()) {
System.out.println(read.readLine());
}
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
source
share