Is it possible to pipe ruby to more / cat / arbitrary programs?

Good morning,

I use Ruby as a scripting layer over another program, and I want to be
able to pipe the output of that program to unix programs. Is this
possible? I’m trying to do something like this:

#this will return output from the program in a string
programoutput = @program.send(input)

#destprogram might be cat, grep, more, less, any such program
programoutput pipeoutput serr = Open3.popen3(destprogram)

Does anyone know of a way to do this?

Thanks, and have a grand old day.
Tuan

“Tuan Bui” tuanbui@cray.com.nospam schrieb im Newsbeitrag
news:bg366r$kcr$1@flapjack.cray.com

Good morning,

I use Ruby as a scripting layer over another program, and I want to be
able to pipe the output of that program to unix programs. Is this
possible? I’m trying to do something like this:

#this will return output from the program in a string
programoutput = @program.send(input)

#destprogram might be cat, grep, more, less, any such program
programoutput pipeoutput serr = Open3.popen3(destprogram)

Does anyone know of a way to do this?

Thanks, and have a grand old day.

You can simply do

system ‘program | other’

Or you can copy it yourself

IO.popen( “ls”, “r” ) do |ls|
IO.popen( “cat”, “w” ) do |cat|
ls.each do |line|
cat.puts line
end
end
end

Regards

robert

I posted a solution which I think does what you want at
http://ruby-talk.org/72502

eexcept I don’t know what distinction you are trying to make between
“programoutput” and “pipeoutput”.

Regards,

Brian.

···

On Wed, Jul 30, 2003 at 11:12:37AM +0900, Tuan Bui wrote:

I use Ruby as a scripting layer over another program, and I want to be
able to pipe the output of that program to unix programs. Is this
possible? I’m trying to do something like this:

#this will return output from the program in a string
programoutput = @program.send(input)

#destprogram might be cat, grep, more, less, any such program
programoutput pipeoutput serr = Open3.popen3(destprogram)

Does anyone know of a way to do this?

Hello fellows,

After spending a few days on this, it seems that redirecting output
between ruby and unix programs is not difficult except in the case of
more. Since more grabs control of the terminal, I have not been able to
figure out a way of piping output to it and having it behave correctly
yet - even using shell.rb does not seem to work with more.

Has anyone ever accomplished using more with a ruby shell?

Tuan

Tuan Bui wrote:

···

Good morning,

I use Ruby as a scripting layer over another program, and I want to be
able to pipe the output of that program to unix programs. Is this
possible? I’m trying to do something like this:

#this will return output from the program in a string
programoutput = @program.send(input)

#destprogram might be cat, grep, more, less, any such program
programoutput pipeoutput serr = Open3.popen3(destprogram)

Does anyone know of a way to do this?

Thanks, and have a grand old day.
Tuan

“Tuan Bui” tuanbui@cray.com.nospam schrieb im Newsbeitrag
news:bgb78i$h10$2@flapjack.cray.com

Hello fellows,

After spending a few days on this, it seems that redirecting output
between ruby and unix programs is not difficult except in the case of
more. Since more grabs control of the terminal, I have not been able to
figure out a way of piping output to it and having it behave correctly
yet - even using shell.rb does not seem to work with more.

Has anyone ever accomplished using more with a ruby shell?

What exactly is a “ruby shell”? You’ll never succeed in have any shell
and more access the terminal at once because there is only one standard
input. Maybe that’s the reason for your problem.

Regards

robert

[snip]

After spending a few days on this, it seems that redirecting output
between ruby and unix programs is not difficult except in the case
of more. Since more grabs control of the terminal, I have not been
able to figure out a way of piping output to it and having it behave
correctly yet - even using shell.rb does not seem to work with more.
Has anyone ever accomplished using more with a ruby shell?
[snip]
Tuan Bui wrote:

Good morning,
I use Ruby as a scripting layer over another program, and I want to
be able to pipe the output of that program to unix programs. Is this
possible? I’m trying to do something like this:
#this will return output from the program in a string
programoutput = @program.send(input)
#destprogram might be cat, grep, more, less, any such program
programoutput pipeoutput serr = Open3.popen3(destprogram)
Does anyone know of a way to do this?
[snip]

I tried less and more in irb with both backticks and using shell.rb.

less <filename> returned a string of the file contents (i.e., with
\n, \t, etc.).
more < filename> behaved the same as above.
shell.less(“”) returned pretty printed text of the entire
file contents (but no ability to page through the file).
shell.more(“”) returned a single newline and then hung until
I interrupted irb.

What correct behavior do you want more to have?

Regards,

Mark

···

On Thursday, July 31, 2003, at 10:40 AM, Tuan Bui wrote: