# How does piping with ruby work?

**URL:** <https://www.ruby-forum.com/t/how-does-piping-with-ruby-work/92652>\
**Category:** Ruby\
**Created:** [April 22, 2007, 4:06pm UTC](https://www.ruby-forum.com/t/how-does-piping-with-ruby-work/92652 "2007-04-22T16:06:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anansi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9fc348/32.png) [@anansi](https://www.ruby-forum.com/u/anansi)\
**Post date:** [April 22, 2007, 4:06pm UTC](https://www.ruby-forum.com/t/how-does-piping-with-ruby-work/92652/1 "2007-04-22T16:06:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anansi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9fc348/32.png) [@anansi](https://www.ruby-forum.com/u/anansi)\
**Post date:** [April 22, 2007, 5:16pm UTC](https://www.ruby-forum.com/t/how-does-piping-with-ruby-work/92652/2 "2007-04-22T17:16:16Z")

</div>

On 4/22/07, anansi [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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
