IntelliJ Java IDE
The moose likes Threads and Synchronization and the fly likes Need help on console app - exec() Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Need help on console app - exec()" Watch "Need help on console app - exec()" New topic
Author

Need help on console app - exec()

Paul Smiley
Ranch Hand

Joined: Jun 02, 2000
Posts: 244
Hi all,
I need a hand with a problem that I'm running into. I haven't messed with threads for a few years, so I'm a bit rusty...
I have an application that needs to run a console app, grab the output and error streams, feed interactive info to the app, read the output and then close the app. For some reason, the app never exits and the threads don't complete.
I have tried:
creating a process
getting error stream and output stream from that process and put each into a thread
start the threads
writing to the process output
doing a waitFor on the process
threads don't complete - they seem to hang up on:
while ((s = bufferedreader.readLine()) != null)
Any ideas?
Thanks,
Paul
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18652
Well, readLine() is looking for a line terminator. Perhaps one of the streams has printed a partial line, with no line terminator? Try replacing readLine() with read(char[]), and print whatever is read.


"I'm not back." - Bill Harding, Twister
Paul Smiley
Ranch Hand

Joined: Jun 02, 2000
Posts: 244
Thanks, Jim, but that doesn't seem to be doing it. It seems as if my interactive commands don't seem to be working. Maybe I'll try to put them in a batch file and run them that way and see if I can get a result.
Hey, long time no talk to!!!
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18652
Yeah, it's been a while since we saw you here. Good to see you're still around.
If you're feeding the app info through the Process's OutputStream, perhaps you need to close the stream so it knows there's no more input?
Putting everything in a batch file (if possible) sounds like a good approach. At least it's easier to debug initially just by running the batch file outside Java. Once that's done (and you're verified that the batch file completes without hanging), it should be relatively simple to call from Java. Um, hopefully.
 
 
subject: Need help on console app - exec()
 
Threads others viewed
Process quandary
reading the standard out from another process
destroy() does not stop Process object
Forking process, DB2 connect
How can I start Ant from a JSP?
IntelliJ Java IDE

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture