I have a program that I run from the command prompt. When it's started, it waits for input in the form of a line of numbers. When I input such a line, it outputs a single digit.
I need to call this program from a Java file, and read the information I get, i.e. the single digit. So I use Runtime.getRuntime().exec("program"), and save the process in a field, and also saving the input and output streams as BufferedReader and BufferedWriter.
The problem now is that I need to figure out how to input the numbers and then hit Enter, and then be able to read the single digit I should get. If I have understood it correctly, if I write something to the Outputstream, I should then be able to read it from the Inputstream. So I use write() followed by newLine() as I figure that will count as Enter, and then I expect to be able to read the digit through readLine(). However, my Java program just pauses at that line, so it seems there is nothing to read. I am sure that the program I want to run outputs a line break after the single digit, so I should be able to read a line.
Furthermore, because I want to confirm that my program is running correctly, I would like to see the input and output inside the Eclipse console, but how can I specify for Eclipse to print those streams to its console?
No replies to this topic
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









