aspose file tools*
The moose likes I/O and Streams and the fly likes IPC through streams Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "IPC through streams" Watch "IPC through streams" New topic
Author

IPC through streams

megha joshi
Ranch Hand

Joined: Feb 20, 2007
Posts: 206
Hi all,

I want to use stream based IPC in Java. To test this I am trying to exec unix more filename command from my java code. Interesting thing is commands like ps, man, ls -l execute fine using the code below. But executing more on a big file , which requires enter input from keyboard occasionally fails. I would like to give input to this unix process from my java code..but I am not sure how to do that. The code I have so far is as follows:
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8907
    
    8

From the JavaDoc for java.lang.Process:

Because some native platforms only provide limited buffer size for standard input and output streams, failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block, and even deadlock.


Your process is likely exceeding the size of the output stream buffer with larger files.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
megha joshi
Ranch Hand

Joined: Feb 20, 2007
Posts: 206
Thanks..Any idea on how to do that..On command line, more usually expects enter key input from user. How to do the same in this code? Thanks again!
Prashant R Kataria
Greenhorn

Joined: Jul 23, 2007
Posts: 20
You will have to do following things:

1) Keep polling on input and error streams continuously, you will have to create separate threads which will do that.
2) get the output stream of process and pass the strings to it by taking them from standard input stream of the application. Use system.in for that.


-
Prashant Kataria
SCJP 5.0

"If you are going through hell, keep going!!!"
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: IPC through streams