Hi all,
I am trying to run an external commands with Kernel.open writing and
reading its standard input / output several times. Unfortunately the
script hangs when trying to read with IO.gets.
Code:
fh = Kernel.open("|hunspell -m", “w+”)
fh.puts “ruby\n”
output = fh.gets()
puts output
fh.puts “rails\n”
output = fh.gets()
puts output
fh.close()
I’ve noticed that the script runs fine if I try to run hunspell without
the ‘-m’ parameter (-m is for morhological analysis). What do I do wrong
here?
Thanks!
Imre Farkas wrote:
Hi all,
I am trying to run an external commands with Kernel.open writing and
reading its standard input / output several times. Unfortunately the
script hangs when trying to read with IO.gets.
Maybe because gets requires a closing newline?
-r
Roger P. wrote:
Maybe because gets requires a closing newline?
-r
…and hunspell puts a closing newline after the output. So that
shouldn’t be the problem.
Imre Farkas wrote:
Hi all,
I am trying to run an external commands with Kernel.open writing and
reading its standard input / output several times. Unfortunately the
script hangs when trying to read with IO.gets.
Code:
fh = Kernel.open("|hunspell -m", “w+”)
fh.puts “ruby\n”
Try here: fh.flush
(or: fh.sync = true after opening it)
I would normally use IO.popen, but I don’t know how/if that differs from
using open in the way you have.