T
Thomas Bl.
Hello.
I have two problems.
First: is there an easy way to redirect data from an incoming IO stream
to an outgoing IO stream, in a nonblocking way? For example, can you run
a console program from Ruby program and redirect the program's output to
STDOUT in realtime? I know one solution that works, but is there
anything better?
Thread::new(IO:open(COMMAND))\
{ |srv|
until srv.eof?
print srv.readpartial(1024)
end
}
Replacing readpartial with sysread also works, and with read_nonblock
works partially.
Second problem: when I use the code above, and at the same time the main
thread is waiting on Process.waitpid for some other program (not the one
of which I redirect the output, but some else), then the waiting doesn't
terminate correctly. It waits until the process finishes, and then,
until there is some data available from the process I'm streaming in the
thread above. And only then the main thread goes on.
I use Windows XP, Ruby 1.8.6.
Here's a blog entry describing the same problem, with no solution:
http://al2o3-cr.blogspot.com/2008/08/iopopen.html .
I have two problems.
First: is there an easy way to redirect data from an incoming IO stream
to an outgoing IO stream, in a nonblocking way? For example, can you run
a console program from Ruby program and redirect the program's output to
STDOUT in realtime? I know one solution that works, but is there
anything better?
Thread::new(IO:open(COMMAND))\
{ |srv|
until srv.eof?
print srv.readpartial(1024)
end
}
Replacing readpartial with sysread also works, and with read_nonblock
works partially.
Second problem: when I use the code above, and at the same time the main
thread is waiting on Process.waitpid for some other program (not the one
of which I redirect the output, but some else), then the waiting doesn't
terminate correctly. It waits until the process finishes, and then,
until there is some data available from the process I'm streaming in the
thread above. And only then the main thread goes on.
I use Windows XP, Ruby 1.8.6.
Here's a blog entry describing the same problem, with no solution:
http://al2o3-cr.blogspot.com/2008/08/iopopen.html .