File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Java interprocess communication Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java interprocess communication" Watch "Java interprocess communication" New topic
Author

Java interprocess communication

krats ram
Greenhorn

Joined: Oct 11, 2009
Posts: 9
I am trying to write some code for twp java programs to communicate. Below are the two programs



and the other program



When I run the caller, the two programs run for a while with output

Whats up Caller !
... Whats up Caller ! got your msg


and then they block. Any suggestions?
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4176
    
  21

You should read and implement this article: When Runtime.exec() won't by Michael Daconta. The vast majority of problems found with Runtime.exec() and Processes in general are addressed their (the fact that he uses Runtime.exec() and you use ProcessBuilder is only significant in that the article was written long ago - everything still applies).

My guess is that your Callee's output buffer is filling. You send 1 line from the caller, the callee sends 2 lines back, and the caller consumers just 1 leaving the other line in the buffer waiting to be consumed. Eventually the buffer fills because you add to it twice as fast as you consume from it.

The article gives a nice class for consuming and reporting all the output from the Process.


Steve
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41526
    
  53
Just starting up the child process, and then using sockets for communication would probably be less brittle.


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java interprocess communication