My goal is to start a cmd process, feed it commands(dir, ipconfig, exit) via the OutputStream and capture the output via the InputStream.
Is this possible with only one process?
If so, what do i need to know to feed the commands properly?
The current way I'm feeding the commands is:
The output I receive is:
At which point the program waits at "line = br.readLine()". It seems to me that the command "dir" isn't being properly executed by the cmd.exe process.
What am I missing to properly send these commands? Or am I really seeing a buffer overflow? [ March 08, 2007: Message edited by: Jonathan Bagshaw ]
Joined: Oct 04, 2006
If you know the commands beforehand you can just add them to the process builder. Otherwise look at the Sun doc for the methods ;
InputStream getErrorStream() Gets the error stream of the subprocess. InputStream getInputStream() Gets the input stream of the subprocess. OutputStream getOutputStream() Gets the output stream of the subprocess.
It is anyway always a good idea to read the input streams, both normal and error, since if you don't they can over run their buffers and your process will die. You probably want to read these streams in separate threads using a StreamGobbler. There's a good article on Processes and example code for a StreamGobbler on Java World "When Runtime.exec() won't" www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
Joined: May 05, 2006
I neglected to add the whole code segment as I'm afraid of looking like I'm not even trying.
I DO have all three code segments.. I will update my original post to show what's going on more accurately.
Edit: Reading the link provided was extremely helpful. [ March 08, 2007: Message edited by: Jonathan Bagshaw ]