redirecting the end of a pipe

T

Thomas Secret

Following interesting problem:
1. I have created two pipe end points via IO.pipe:
stdin_read,stdin_write=IO.pipe

2. I have forked of a child, and redirected stdin of the child with:
$stdin.reopen(stdin_read)

3. In the parent process, I have used the other end of the pipe to write
to the stdin of the child:
stdin_write.puts "word1"

At that point, I am finished sending stuff through the pipe
automatically.
However, I am unsure whether my child may need any further input.
Because of that, I want to redirect the pipe end 'stdin_write' in the
parent to stdin, so that stuff coming in through stdin gets send on
through stdin_write (thus ending up in the stdin of the child).
Question: How do I do that?

The obvious first try of stdin_write.reopen($stdin) does not work, as it
destroys the pipe connection.
Of course I could just keep polling $stdin, and send anything I get on
to stdin_write, but really, ughh...

Does anybody have a nicer solution or idea?
 
T

Thomas Secret

Thank you for your answer.

I've now done precisely what I had hoped to avoid: Keep polling for new
input, and pass on anything I get. As I don't control the child,
apparently the only thing I can do. At least it works...
 
R

Robert Klemme

2010/6/28 Thomas Secret said:
Thank you for your answer.

You're welcome.
I've now done precisely what I had hoped to avoid: Keep polling for new
input, and pass on anything I get. As I don't control the child,
apparently the only thing I can do. At least it works...

IMHO "polling" is not exactly the right term for this. Rather you
read and block until more data is available - unless you use non
blocking IO.

Kind regards

robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top