what the heck is standard input

01 Oct 2015 | |

“it’s anything that is non-standard.” (I see an ebook there somewhere)


A ruby script can get input from a keyboard. You know, when you open a terminal, and call a script with arguments. But also the source could be text redirected from another source. To ruby these are the same thing, in that they are processed the same way.

This source of input is called standard input. It allows programs to communicate with each other simply with just text. We also have the complementary “streams” on the other end, called standard output and standard error.

From the Man-pages (Manly yes…but I like it too!)

Under normal circumstances every UNIX program has three streams opened for it when it starts up, one for input, one for output, and one for printing diagnostic or error messages. These are typically attached to the user’s terminal (see tty(4) but might instead refer to files or other devices, depending on what the parent process chose to set up. The input stream is referred to as “standard input”; the output stream is referred to as “standard output”; and the error stream is referred to as “standard error”. These terms are abbreviated to form the symbols used to refer to these files, namely stdin, stdout, and stderr.

Pipeline chains

Chains of programs or commands strung together to the output from one becomes input to the first.

Here is an example of listing active processes > that contain the word ruby > and then displaying the first whitespace column, which is the PID.

 $ ps ax | grep ruby | cut -d' ' -f1

cut command

Used to “cut out” sections of a line.

 -d, --delimiter=DELIM   >  use character DELIM instead of a tab for the field delimiter. We use a SPACE here
 -f, --fields=LIST  > select only these fields on each line, here select the first field.

This example uses commands but the same thing can be done with ruby scripts. If the program is set up to use standard input then it can get it’s input from different types of sources, not needed to know where. Because its processed the same.

comments powered by Disqus(comments off)

Older · View Archive (32)

How to set up your github blog with your domain host.

“As Strother Martin once said in cool hand luke…What we’ve got here…is a failure to communicate…”


AS400 Resume

“Hard work makes up for lack of brains”…Jason Suma’s Dad