Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

IPC through streams

 
megha joshi
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9320
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
megha joshi
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic