您可以使用
IO.pipe并告诉
Process.spawn使用重定向的输出,而无需外部gem。
当然,仅从Ruby 1.9.2开始(我个人建议1.9.3)
以下是Spinach BDD在内部用于捕获输出和err输出的简单实现:
# stdout, stderr pipesrout, wout = IO.pipererr, werr = IO.pipepid = Process.spawn(command, :out => wout, :err => werr)_, status = Process.wait2(pid)# close write ends so we could read themwout.closewerr.close@stdout = rout.readlines.join("n")@stderr = rerr.readlines.join("n")# dispose the read ends of the pipesrout.closererr.close@last_exit_status = status.exitstatus原始来源位于features / support /
filesystem.rb中
强烈建议您阅读Ruby自己的Process.spawn文档。
希望这可以帮助。
PS:我将超时实现留给您做功课;-)



