Question: how to do (repeated) bidirectional communication with another process via stdin/stdout?

Hello,

I 'am rather new to Ruby, so please excuse me in case this question might sound stupid, easy etc., but I have not found anything useful concerning my problem on this mailing list or other internet resources about Ruby.
My question is:
Is it possible to perform a repeated bidirectional communication between
my Ruby program and another process via stdin/stdout ?
I need to open the other program (start a process) and then conduct a “dialog” with it.
The other program has a communication protol, which takes an interface string as an input (on stdin) and synchronously returns a response interface string as an output (on stdout).
A typical communication would be like this :

(1) Ruby program opens other process .
(2) Ruby program sends an interface string to other process on stdout.
(the first call would be a login for db-connection and initialization by the system).
(3) the other process executes the called function and returns the response to ruby .
(4) the Ruby program reads the response string from stdin and parses it.
(5) the Ruby program sends the next interface call to the process.

… this type of call - response communication protocol. Step (2) -(4)
can be repeated n times on the open connection channel.

(n) the Ruby program closes the other process when it is finished.

My problem is, that the standard Ruby IO class seems not to allow this type of repeated
bidirectional communication dialog with another process.
Something like ke = IO.popen(“ke.exe”, “r+”) would give me a bidirectional communication channel,
but unfortunatly it is not possible to read from the I/O stream until the write end of the I/O stream is closed. The write end cannot be reopened for a second call.
(This means I would have to do … ke.close_write() … in order to be able to read the response, but not be able to do a second ke.print(mySecondInterfaceCall) method call).
I have written a Ruby API library for the interface format of this system
(in order to create the call interfaces and parse the response),
but I’ m quite stuck with the communication problem I tried to describe above.
I would appreceate very much if someone could give me a hint how to accomplish this task with Ruby.(It should possibly run under on Windows).

regards,

Carsten

···

FreeMail in der Premiumversion! Mit mehr Speicher, mehr Leistung, mehr
Erlebnis und mehr Pramie. Jetzt unter http://club.web.de/?mc=021105

Remember to flush after writing. Or, set the IO to auto-flush.

– Dossy

···

On 2002.06.16, Carsten Gronski cgronski@web.de wrote:

My problem is, that the standard Ruby IO class seems not to allow this
type of repeated bidirectional communication dialog with another
process. Something like ke = IO.popen(“ke.exe”, “r+”) would give me a
bidirectional communication channel, but unfortunatly it is not
possible to read from the I/O stream until the write end of the I/O
stream is closed.


Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)