In the past two days I tried to rewrite a bunch of popen based code that drives an external tool I need for a webapp I’m coding (in Rails). The problems arose because IO::popen hung when used behind the webapp with a 5K+ input sent it from the standard input. In my “journey” I learnt about RubyInline, nice tool to wrap C/C++ code, I learnt more about IPC world, Ruby support for I/O and more so I was happy learning new stuff but my problem was still there.
Here comes session library (and his author Ara T. Howard) to the rescue
His latest version (2.4.0 at the time) solves all my problems with hangs.
Good job Ara, very good job.
ps. here is the solution
cmd = 'theprocesstodrive' text = 'thetexttopasstothestdinoftheaboveprocess' session = Session.new result = session.execute cmd, :stdin => textNice, isn’t it?
















