Forum: Ruby How does piping with ruby work?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
anansi (Guest)
on 2007-04-22 16:06
(Received via mailing list)
Hi,
I have a ruby script which does some calculations and saves the result
in a variable. Now this script should start another external application
and pipe this variable's content into the gets() function of this
external app. Any idea how I can do this?

greets






--
                   (
                    )
                   (
             /\  .-"""-.  /\
            //\\/  ,,,  \//\\
            |/\| ,;;;;;, |/\|
            //\\\;-"""-;///\\
           //  \/   .   \/  \\
          (| ,-_| \ | / |_-, |)
            //`__\.-.-./__`\\
           // /.-(() ())-.\ \\
          (\ |)   '---'   (| /)
           ` (|           |) `
     jgs     \)           (/

one must still have chaos in oneself to be able to give birth to a
dancing star
botp (Guest)
on 2007-04-22 17:16
(Received via mailing list)
On 4/22/07, anansi <kazaam@oleco.net> wrote:
> I have a ruby script which does some calculations and saves the result
> in a variable. Now this script should start another external application
> and pipe this variable's content into the gets() function of this
> external app. Any idea how I can do this?

This is just a crude example.
$ cat test.rb
x=gets.chomp
puts "You piped: #{x}"

[botp@pc4family:~/Desktop/: Sun Apr 22 22:54:00]
$ irb
irb(main):001:0> a="this is a test"
=> "this is a test"
irb(main):003:0> system "echo #{a} | ruby test.rb"
You piped: this is a test
=> true
irb(main):004:0>

pls take a look at popen and Ara's session library.

kind regards -botp
This topic is locked and can not be replied to.