View Full Version : Std streams
DBQ
September 4th, 2007, 08:02 AM
Hey Guys,
Some processes (ie more), can have a piped input, and keyboard input at the same time. How is this possible in bash, since each process can have only one stdin stream? I will spend some time looking at the source , but if anybody has a simple explanation it'd be cool.
lisati
September 4th, 2007, 08:08 AM
I'm not sure what arrangements there are in BASH but some versions of the C programming language have multiple "std" i/o streams - these include "stderr".
DBQ
September 4th, 2007, 08:10 AM
How does C do that?
lisati
September 4th, 2007, 08:17 AM
How does C do that?
I'm not sure of the exact details, I'm a bit rusty on "C". If memory serves, for console programs, most output involving the screen goes through "stdout", e.g. fprint(stdout,message)
"stderr" is normally used for error messages, but the idea is pretty much the same e.g. fprint(stderr,message)
EDIT: p.s. "stdout" and "stderr" are often treated as "files" by C that are normally associated with the screen (terminal, console, insert word of choice)
Lux Perpetua
September 4th, 2007, 11:13 AM
Hey Guys,
Some processes (ie more), can have a piped input, and keyboard input at the same time. How is this possible in bash, since each process can have only one stdin stream? I will spend some time looking at the source , but if anybody has a simple explanation it'd be cool.I actually looked at the source code of the more utility some years ago when I was learning C trying to understand issues like this, just like you're trying to do. If I recall correctly, it simply opens /dev/tty for input.
edit. To see /dev/tty in action, try the following in your terminal:
$ echo "Here is some text" > /dev/tty
$ cat < /dev/tty > test.txt # Then type some text and press control-D
$ cat test.txt
DBQ
September 4th, 2007, 01:51 PM
what about something like ps -aux | more ?
Lux Perpetua
September 4th, 2007, 04:09 PM
Do you know anything about files and streams? A program can have many files open at once. So a program can receive input from many different places. If its input is redirected, so stdin no longer refers to the terminal, the program can still access the terminal via special files in the dev directory.
Powered by vBulletin® Version 4.2.2 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.