Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am new to Linux. And I am using Red Hat Enterprise Version 5. There is a ruby program which use standard input as its input (e.g. the Ruby program process input from standard input). I think standard input should be keyboard, correct?

So, I think other kinds of input (non-standard input) should not work (i.e. the ruby program should not be able to read input from such non-standard input), but actually I have tried using pipe works, I am so confused because I think pipe should be some other kinds of input -- other than standard input, why it could work? i.e. put text "123" in abc.txt with pipe, could achieve the same result as using keyboard as input to type "123" for the ruby program.

Here is the sample which works and makes me confused,

cat abc.txt | ~/test/rubysrc/foo.rb

thanks in advance, George

share|improve this question

migrated from Jun 10 '11 at 10:21

This question came from our site for professional and enthusiast programmers.

This question appears to be conflating "non-standard" with "non-keyboard". – JdeBP Jun 10 '11 at 10:54
up vote 2 down vote accepted

Use $stdin.isatty if you want to try to prevent non-terminal input. Do note that there are ways around this if the user is determined enough.

share|improve this answer
So, the right process of the process cannot process keyboard input if connected by pipe? – George2 May 15 '10 at 15:51
Not via stdin. It can still open up /dev/tty though, and get input from there. – Ignacio Vazquez-Abrams May 15 '10 at 15:53
Thanks, question answered! – George2 May 15 '10 at 16:02

Pipe works as a "redirector" from STDOUT (which does cat abc.txt) to STDIN (which accepts the foo.rb script.

IMHO this belongs on

share|improve this answer

Actually, the pipe connects the left process's stdout to the right process's stdin, so it makes sense that this works. See also

(And yes, this should probably go to

share|improve this answer
So, the right process cannot process keyboard input if connected by pipe? – George2 May 15 '10 at 15:50

Pipes work by connecting standard input and output of one process to other processes, simulating a user typing on his keyboard. This allows processes to be connected together without having to know about each other, or used directly by the user from his keyboard.

Wikipedia has a nice writeup.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .