keyongtech


  keyongtech > ruby > 03/2008

 #1  
03-12-08, 07:03 AM
Nikhil Warade
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.
 #2  
03-12-08, 07:23 AM
Friedrich Dominicus
Nikhil Warade <newarade47> 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
 #3  
03-12-08, 07:37 AM
Nikhil Warade
Friedrich Dominicus wrote:
> Nikhil Warade <newarade47> 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 [url down] where we need to input using
STDIN
You don't seem to have used STDIN
 #4  
03-12-08, 08:05 AM
Friedrich Dominicus
Nikhil Warade <newarade47> writes:

> Friedrich Dominicus wrote:
>
> Please check [..] 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
 #5  
03-12-08, 08:11 AM
Phillip Gawlowski
Nikhil Warade wrote:
Similar Threads
Best way to input from stdin?

I'm writing a program that supports input from stdin. To be able to do that I tend to rely on a simple loop that tests the return of fgets(), such as the following...

Any way to take a word as input from stdin ?

I searched the c.l.c archives provided by Google as Google Groups with "word input" as the key words and did not come up with anything good. C++ has std::string for taking...

How to accept input from stdin?

Hi, I try to make a wrapper around an existing program, which would behave exactly the same as the original one. But my following attempt was failed. Would you pleaes let me...

getting input from stdin

Hi Im new to unix scripting and now Im trying to get user input from stdin and this is what I did echo "enter your name: " read name and it will run with the pointer to...

Checking available input on stdin

I know this has probably come up frequently, but couldn't find a satisfactory reference... I have some code which needs to read from stdin but must not block waiting for...


All times are GMT. The time now is 01:14 AM. | Privacy Policy