# Input using stdin

**URL:** <https://rubytalk.org/t/input-using-stdin/45111>\
**Category:** ruby-talk\
**Created:** [12 March 2008 07:03 UTC](https://rubytalk.org/t/input-using-stdin/45111 "2008-03-12T07:03:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nikhil\_Warade](https://avatars.discourse-cdn.com/v4/letter/n/a8b319/32.png) [@Nikhil\_Warade](https://rubytalk.org/u/Nikhil_Warade)\
**Post date:** [12 March 2008 07:03 UTC](https://rubytalk.org/t/input-using-stdin/45111/1 "2008-03-12T07:03:26Z")

</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.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Friedrich\_Dominicus2](https://avatars.discourse-cdn.com/v4/letter/f/b38774/32.png) [@Friedrich\_Dominicus2](https://rubytalk.org/u/Friedrich_Dominicus2)\
**Post date:** [12 March 2008 07:29 UTC](https://rubytalk.org/t/input-using-stdin/45111/2 "2008-03-12T07:29:59Z")

</div>

Nikhil Warade \<newarade47@gmail.com\> 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 remove just-for-news- to reply via e-mail.

---

<div class="post-metadata">

**Author:** ![Nikhil\_Warade](https://avatars.discourse-cdn.com/v4/letter/n/a8b319/32.png) [@Nikhil\_Warade](https://rubytalk.org/u/Nikhil_Warade)\
**Post date:** [12 March 2008 07:37 UTC](https://rubytalk.org/t/input-using-stdin/45111/3 "2008-03-12T07:37:17Z")

</div>

Friedrich Dominicus wrote:

> Nikhil Warade \<newarade47@gmail.com\> 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

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Friedrich\_Dominicus2](https://avatars.discourse-cdn.com/v4/letter/f/b38774/32.png) [@Friedrich\_Dominicus2](https://rubytalk.org/u/Friedrich_Dominicus2)\
**Post date:** [12 March 2008 08:09 UTC](https://rubytalk.org/t/input-using-stdin/45111/4 "2008-03-12T08:09:54Z")

</div>

Nikhil Warade \<newarade47@gmail.com\> writes:

> Friedrich Dominicus wrote:
> 
> > Nikhil Warade \<newarade47@gmail.com\> 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

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",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;^^^^^^ here is your gets

Friedrich

> **···**
>
> --  
> Please remove just-for-news- to reply via e-mail.

---

<div class="post-metadata">

**Author:** ![Phil](https://avatars.discourse-cdn.com/v4/letter/p/e95f7d/32.png) [@Phil](https://rubytalk.org/u/Phil)\
**Post date:** [12 March 2008 08:11 UTC](https://rubytalk.org/t/input-using-stdin/45111/5 "2008-03-12T08:11:30Z")

</div>

Nikhil Warade wrote:

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

> **[Standard streams |](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_.28stdin.29)**
>
> Standard input is a stream from which a program reads its input data. The program requests data transfers by use of the read operation. Not all programs require stream input. For example, the dir and ls programs (which display file names contained in a directory) may take command-line arguments, but perform their operations without any stream data input.
> Unless redirected, standard input is inherited from the parent process. In the case of an interactive shell, that is usually associated with t...
