• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need help on console app - exec()

 
Paul Smiley
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paul Smiley
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!