wood burning stoves 2.0*
The moose likes Java in General and the fly likes Process object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Process object" Watch "Process object" New topic
Author

Process object

Jonathan Bagshaw
Greenhorn

Joined: May 05, 2006
Posts: 14
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 ]
Nicole Lacoste
Ranch Hand

Joined: Oct 04, 2006
Posts: 30
Hi,

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

Niki
Jonathan Bagshaw
Greenhorn

Joined: May 05, 2006
Posts: 14
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 ]
Jonathan Bagshaw
Greenhorn

Joined: May 05, 2006
Posts: 14
My output stream was not properly formed either.


Should be
 
Don't get me started about those stupid light bulbs.
 
subject: Process object
 
Similar Threads
Problem with HP UX ia64 while using Process proc = Runtime.getRuntime().exec( command );
Strange problem with Runtime.exec()
Implementing runAs in Java
Another Runtime Problem
Execute "echo $BASHPID" in Linux using Java