Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Sending a stream to a process  RSS feed

 
Tim Manchester
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy,

For fun I wrote an app that launches a daemon process that just sits and listens to stdin and echoes what it gets out to stdout. The main app has the Process object after it calles Runtime.exec() to launch the new process. The Process object allows me to get it's stdin and stdout through calls to Process.getInputStream() and Process.getOutputStream(), hooray.

Now the problem is my app has an InputStream which is the daemon process' stdin, but how do I use it to send a message to the daemon? There is no InputStream.write() method. By the same token, how do I use the daemon process' OutputStream to get the messages it's sending back? Any suggestions?

I do know that I could use a database or some message queue system here but I'm trying to do this just with streams.

Regards,

Tim Manchester
[ September 12, 2006: Message edited by: Tim Manchester ]
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Those streams are named from your point of view - output is what you write to and the process reads as stdin, input is what you read which comes from the process stdout. I have to look this up almost every time, feel like I'm counting on my fingers.


getOutputStream

public abstract OutputStream getOutputStream()

Gets the output stream of the subprocess. Output to the stream is piped into the standard input stream of the process represented by this Process object.

Implementation note: It is a good idea for the output stream to be buffered.

Returns:
the output stream connected to the normal input of the subprocess.



When Runtime Exec Won't has good coverage of this stuff, particularly handling streams on separate threads.
[ September 12, 2006: Message edited by: Stan James ]
 
Tim Manchester
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah very good. I'll check out that link too. OK, let me back at this...

Regards,

Tim Manchester
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!