On Tue, Mar 06, 2007 at 08:09:48AM +0900, Kyle Schmitt wrote:
> I think I chose a bad example, I don't want to just find things :) but
> it looks like that's the problem people have aimed at.
> 
> The %x{} is very useful for some things I admit.

It seems to me that what you want is not to send the command's output
directly into irb (which would treat it as a series of ruby commands and try
to execute them), but to stuff the command's output into a pipe, which you
can then read from using Ruby in irb at your leisure.

This is easy if you issue the shell command itself within irb:

irb(main):001:0> IO.popen("cat /etc/passwd","r").each_line { |x| puts x }
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/bin/sh
...

Otherwise, you can use a fifo (named pipe).

[screen 1]
$ mkfifo toirb
$ cat /etc/passwd >toirb

[screen 2]
$ irb
irb(main):001:0> File.open("toirb") { |f| f.each_line { |x| puts x } }
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/bin/sh
...
=> #<File:toirb (closed)>
irb(main):002:0>

This easily solves the problem of which irb process the output gets directed
to - both the sending side and the receiving side refer to the pipe by name.
You can of source make your own syntactic sugar wrappers.

HTH,

Brian.