public static void main(String[] args) {
try {
String line;
InputStream stdout = null;
OutputStream stdin = null;
Process process = Runtime.getRuntime().exec("test.exe");
stdout = process.getInputStream ();
stdin = process.getOutputStream ();
line = "Hello World" + "\n";
stdin.write(line.getBytes() );
stdin.flush();
stdin.close();
BufferedReader brCleanUp =
new BufferedReader (new InputStreamReader (stdout));
while ((line = brCleanUp.readLine ()) != null) {
System.out.println ("[Stdout] " + line);
}
brCleanUp.close();
}
catch(Exception e){
System.out.println("Error\n");
}
}
The code above allows a Java class to write in the stdin of "test.exe" (C program) and to read its stdout Now, how can I make a Java Class which listens for the events on the stdout of a C program. That is a Java event listener that will be called each time a new line is written in the stdout of the C program