# Input using stdin

**URL:** <https://www.ruby-forum.com/t/input-using-stdin/131657>\
**Category:** Ruby\
**Created:** [March 12, 2008, 8:03am UTC](https://www.ruby-forum.com/t/input-using-stdin/131657 "2008-03-12T08:03:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![newarade47](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/838e76/32.png) [@newarade47](https://www.ruby-forum.com/u/newarade47)\
**Post date:** [March 12, 2008, 8:03am UTC](https://www.ruby-forum.com/t/input-using-stdin/131657/1 "2008-03-12T08:03:33Z")

</div>

How can I give input to a program using STDIN  
Suppose I want the program to take the value x=10  
On some other site i found it as STDIN.read,but its not working.

---

<div class="post-metadata">

**Author:** ![newarade47](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/838e76/32.png) [@newarade47](https://www.ruby-forum.com/u/newarade47)\
**Post date:** [March 12, 2008, 8:30am UTC](https://www.ruby-forum.com/t/input-using-stdin/131657/2 "2008-03-12T08:30:45Z")

</div>

Nikhil W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> How can I give input to a program using STDIN  
> Suppose I want the program to take the value x=10  
> On some other site i found it as STDIN.read,but its not working.

print("Give me a string ");  
STDOUT.flush  
a\_string = gets  
print(“You gave me ‘#{a\_string}’”)

Regards  
Friedrich

---

<div class="post-metadata">

**Author:** ![newarade47](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/838e76/32.png) [@newarade47](https://www.ruby-forum.com/u/newarade47)\
**Post date:** [March 12, 2008, 9:10am UTC](https://www.ruby-forum.com/t/input-using-stdin/131657/3 "2008-03-12T09:10:46Z")

</div>

Nikhil W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> > a\_string = gets  
> > print(“You gave me ‘#{a\_string}’”)
> > 
> > Regards  
> > Friedrich
> 
> Please check [http://codegolf.com/reverse](http://codegolf.com/reverse) where we need to input using  
> STDIN  
> You don’t seem to have used STDIN  
> gets works on the standard input if you insist you can write  
> STDIN.gets if that makes you feel better

STDIN.public\_methods.sort  
=\> [“\<\<”, “==”, “===”, “=~”, “ **id** ”, “ **send** ”, “all?”, “any?”,  
“binmode”, “class”, “clone”, “close”, “close\_read”, “close\_write”,  
“closed?”, “collect”, “detect”, “display”, “dup”, “each”, “each\_byte”,  
“each\_line”, “each\_with\_index”, “entries”, “eof”, “eof?”, “eql?”,  
“equal?”, “extend”, “fcntl”, “fileno”, “find”, “find\_all”, “flush”,  
“freeze”, “frozen?”, “fsync”, “getc”, “gets”,  
^^^^^^ here is your gets

Friedrich

---

<div class="post-metadata">

**Author:** ![newarade47](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/838e76/32.png) [@newarade47](https://www.ruby-forum.com/u/newarade47)\
**Post date:** [March 12, 2008, 8:37am UTC](https://www.ruby-forum.com/t/input-using-stdin/131657/4 "2008-03-12T08:37:25Z")

</div>

Friedrich D. wrote:

> Nikhil W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:
> 
> > How can I give input to a program using STDIN  
> > Suppose I want the program to take the value x=10  
> > On some other site i found it as STDIN.read,but its not working.
> 
> print("Give me a string ");  
> STDOUT.flush  
> a\_string = gets  
> print(“You gave me ‘#{a\_string}’”)
> 
> Regards  
> Friedrich

Please check [http://codegolf.com/reverse](http://codegolf.com/reverse) where we need to input using  
STDIN  
You don’t seem to have used STDIN

---

<div class="post-metadata">

**Author:** ![newarade47](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/838e76/32.png) [@newarade47](https://www.ruby-forum.com/u/newarade47)\
**Post date:** [March 12, 2008, 9:12am UTC](https://www.ruby-forum.com/t/input-using-stdin/131657/5 "2008-03-12T09:12:32Z")

</div>

Nikhil W. wrote:

> STDIN  
> You don’t seem to have used STDIN
> 
> Please check [http://codegolf.com/reverse](http://codegolf.com/reverse) where we need to input using  
> [Standard streams - Wikipedia](http://en.wikipedia.org/wiki/Standard_streams#Standard_input_.28stdin.29)
