Does anyone know if it’s possible to pipe the output of a command to a
running instance of irb?
I said it was silly.
But it seems like it would be really useful. Something along the lines
of
#nix>find ./ -name ".foo" |toirb
that would dump the output from find (as an array? As text?) to an
already active instance of IRB.
Does such a thing exist?
If not I feel confident enough to try and butcher up something like it.
My guess is the instance of IRB would have to instantiate some object
(lets call it P), and then when the |toruby command was used, the P
object could be queried for the list.
Does anyone know if it’s possible to pipe the output of a command to a
running instance of irb?
I said it was silly.
But it seems like it would be really useful. Something along the lines of
#nix>find ./ -name ".foo" |toirb
that would dump the output from find (as an array? As text?) to an
already active instance of IRB.
I don’t mean to say that I have already achieved these things or that I
have already reached perfection! But I keep working toward that day
when I will finally be all that Christ Jesus saved me for and wants me
to be. Philip. 3: 12, NLT http://www.iit.edu/~meyedou/
Sorry, I didn’t realize you were probably not handling a huge amount
of data… in which case, it doesn’t really matter if the file is a fifo
or not.
You still can do the same trick with sockets, though, but it won’t
come much easier… The main problem is you need a server somewhere.
Named pipes are an option for this, as well as tcp networking (though
the latter is admittedly way more heavy). Apart from that, I don’t see
other techniques, unless you want to dwell into semaphores (but I’m not
an expert in IPC).
You could set up a DRb server in IRB and make “toruby” an DRb client
that sends data off to the server. In any case you have solve the
problem how toruby knows which IRB to talk to. Either you allow just
one IRB session on your system or you have to provide toruby with some
kind of input that shows him the way (env var, command line arg).
Personally I don’t feel that this is very useful. There is `` and %x{}
as was shown already. And for finding files there is Dir[] and
Find.find which both work without any external process.
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.
I’ve got some areas where a pipe-to-ruby would be really nice. I’m
sure if it’s there I’ll find other uses for it too.
Good point about the choice of which irb to send it to though. I was
planning on looking into how screen finds screens to attach to. If
only one is open that belongs to that user, it automagically attaches
to that one, if there is more than one, it politely coughs and
requests that you specify one. Sadly that does make things a little
more complex.
Lets just settle on, I’m going to write this since it doesn’t exist in
the form I want to use. And I’m going to write it as an object the
client has to open.
Now, moving on… Would something like this seem bad (style in ruby,
in general, or in functionality)
in irb-----------
require ‘silly/Kpipe’
mine=Kpipe.new
puts mine.id
1701
then in the shell (a non find example!)-----------
#*nix> mpg123 silly.mp3 -s |toruby 1701
then back in irb-----
mine.each_byte{|i| likeiknowwhattodowithwavdata(i) }
On Tue, Mar 06, 2007 at 08:09:48AM +0900, Kyle S. 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:
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.
only one is open that belongs to that user, it automagically attaches
in irb-----------
require ‘silly/Kpipe’
mine=Kpipe.new
puts mine.id
1701
then in the shell (a non find example!)-----------
#*nix> mpg123 silly.mp3 -s |toruby 1701
then back in irb-----
mine.each_byte{|i| likeiknowwhattodowithwavdata(i) }
Yeah, you could use the port number (probably using Unix domain sockets)
as that id.
Btw, how do you want to deal with multiple submissions? Do you want to
treat them in IRB as a single stream or as individual streams? The
first is probably easier with a pipe or a file, the latter seems easier
with a socket.