I have code similar to the following that interacts with gdb from Java. I start the process with gdb and then get the process’s streams. I have a thread that constantly reads the output of the process (using procOut) and prints it to the screen, and I send commands to gdb using procIn.println("some_command") –
Process proc = new ProcessBuilder("gdb").start;
procOut = new BufferedReader(new InputStreamReader(proc.getInputStream()));
procErr = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
procIn = new PrintWriter(new BufferedWriter(new OutputStreamWriter(proc.getOutputStream())));
However if I change procIn to a BufferedWriter –
procIn = BufferedWriter(new OutputStreamWriter(proc.getOutputStream()));
and use procIn.write("some_command"), it doesn’t work and gdb doesnt get the input. Anyone know why this happens?
You have to do a flush() on the BufferedWriter to make sure it goes out.