Now that has excess flushes, but they don’t seem to help. Here’s a program
that tries to run that program, answer its question, and collect the
bounced answer. It has excess flushes too. It also cheats by knowing the
length of the question. My target program can cheat like this too:
require 'fcntl'
pipe = IO.popen( "ruby qa.rb", "r+" )
# pipe.close_write()
pipe.fcntl(Fcntl::F_SETFL, Fcntl::O_NONBLOCK)
def absorb pipe
contents = ''
loop do
begin
nu = pipe.readchar()
rescue
nu = nil
end
contents += nu.chr() if nu != nil
break if contents.size() > 9
end
puts contents
end
absorb pipe
pipe.write('yo\n')
pipe.flush()
absorb pipe
Please observe I’m not asking how to popen into the ruby executable itself.
My ultimate target is a binary executable, so telling me how to change the
options of the inner ruby won’t help.
Now that has excess flushes, but they don’t seem to help. Here’s a program
that tries to run that program, answer its question, and collect the
bounced answer. It has excess flushes too. It also cheats by knowing the
length of the question. My target program can cheat like this too:
for i in retval[0]
str = i.read(1)
print str
return if str == nil
contents += str
if contents.size() == 9 then
pin.write("yo\n")
print "yo\n"
end
STDOUT.flush()
end
end