From: Andrew Wagner Date: 2013-03-16T07:34:38+09:00 Subject: IO buffering problem --20cf307d052cefdcb104d7fe25d0 Content-Type: text/plain; charset=UTF-8 All, I'm writing a chess program that has a simple text-based interface. It's designed to be run by another program, which has a nice UI. Here's the program as it stands now, whittled to the simplest possible use case: i = 0 moves = ["a7a6","a6a5","a5a4","a4a3"] $stdin.each do |command| if command.start_with?("protover") $stdout.puts "feature ping=0 setboard=1 ics=1 usermove=1" elsif command.start_with?("usermove") $stdout.puts "move #{moves[i]}" i+=1 end $stdout.flush end The "protover" thing is needed to tell the UI program how to initialize the protocol, and then every time a move is made, the UI program sends "usermove " to my program, which responds with "move ". If I run this by itself, I can happily enter a few 'usermove' commands manually, and get any number of canned moves back. However, when I run this under the UI, I get an Interrupt: bin/winboard.rb:3:in `each': Interrupt from bin/winboard.rb:3:in `
' I know that the UI program is pretty reliable, so I'm missing something in the way that I'm handling IO buffering or something. If you want the nitty gritty details, you can see them at http://www.gnu.org/software/xboard/engine-intf.html . I'm running on MacOSX. Any suggestions? --20cf307d052cefdcb104d7fe25d0 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
All,
I'm writing a chess program that has a = simple text-based interface. It's designed to be run by another program= , which has a nice UI. Here's the program as it stands now, whittled to= the simplest possible use case:

i =3D 0
moves =3D ["a7a= 6","a6a5","a5a4","a4a3"]
$stdi= n.each do |command|
=C2=A0 if command.start_with?("protover&= quot;)
=C2=A0 =C2=A0 $stdout.puts "feature ping=3D0 setboard=3D1 ics=3D1= usermove=3D1"
=C2=A0 elsif command.start_with?("usermo= ve")
=C2=A0 =C2=A0 $stdout.puts "move #{moves[i]}"=
=C2=A0 =C2=A0 i+=3D1
=C2=A0 end
=C2=A0 $stdout.flush
end

The "protover" thing is needed to tell the UI program= how to initialize the protocol, and then every time a move is made, the UI= program sends "usermove <some move>" to my program, which = responds with "move <my move>".=C2=A0

If I run this by itself, I can happily ente= r a few 'usermove' commands manually, and get any number of canned = moves back. However, when I run this under the UI, I get an Interrupt:

bin/winboard.rb:3:in `each': Inter= rupt
from bin/winboard.rb:3:in `<main>'

<= /div>
I know that the UI program is pretty reliable, so I'm m= issing something in the way that I'm handling IO buffering or something= . If you want the nitty gritty details, you can see them at http://www.gnu.org/softwar= e/xboard/engine-intf.html . I'm running on MacOSX. Any suggestions?=

--20cf307d052cefdcb104d7fe25d0--