I'm trying to wrap Ruby around a program, interfacing with it via
stdin/stdout. Say I have the following C program:
#include <stdio.h>
int main() {
const char buf[128];
while (1) {
printf("enter: ");
gets(buf);
printf("result: %s\n", buf);
}
return 0;
}
And the following ruby script:
#!/usr/bin/env ruby
require 'open3'
gin, gout, gerr = Open3.popen3('./mytest.exe')
gout.sync = true
STDOUT.sync = true
while line = gout.gets
puts 'recv:' + line
end
I expect it to print "recv: enter: " but it doesn't. At least on ruby
1.8.2 under cygwin under windows, Ruby blocks on the gout.gets. I've
tried adding STDOUT.sync = true and gout.sync = true but that doesn't
help. I tested it on Fedora/Ruby 1.8.2 and it doesn't seem to work there
either. Am I doing something wrong, or is this just a limitation of
popen?