The Only way to learn is ...........do!
Visit my blog http://inaved-momin.blogspot.com/
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Charles Hargrave wrote:
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Just an observation, but that seems like a lot of text to expect a user to type in correctly to make your program do something.
It sounds like you want your Java program to start up some other program, then have your Java program pass the user's input (commands) to the other program while it is running? If that is what you meant, you need to get that Process instance's output stream (see ProcessBuilder.getOutputStream(); it'll connect to the STDIN of the other program) and write the user's commands to it. If you want to feed in the contents of a file to that program's STDIN, in Java 1.7, look at ProcessBuilder's redirectInput(File file) method.
You might not need to bring up another console window; you could use the same one that the Java program is using but you'll need to put in code to know when to quit sending input to the other program. If the other program is simple enough that it can use command line parameters to tell it what to do, I would go with that approach. With the command line parameter approach, you can check all of the parameters before you try to execute the other program.
Without knowing any details about what the program is supposed to do, I can't make any other recommendations for fear of misdirecting you. Good luck to you.
CNH
The Only way to learn is ...........do!
Visit my blog http://inaved-momin.blogspot.com/
naved momin wrote:
thanks for the help charles..
what i m doing is quite simple but my problem is process gets hanged
let me rephrase it to you , i have a file (HelloWorld.java) this file has two statements first and second accept user input and echo that out using
so when i m executing that file through Runtime.exe() , i m getting the input ie
enter msg
but when i m entering the msg the process gets hanged up or even deadlock
so i m searching solution for that , let me give you the code so that you can understand what is going on and can even isolate problem ?