470,810 Members | 1,431 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,810 developers. It's quick & easy.

why standard files?

I heard people saying when executing a program 3 standard files will be
opened namely STDIN, STDOUT, STDERR. Is it so? if so what is the
purpose and what each of them stands for?

Explanation of the concept, Guidence to / provision of resources will
be of great help.

Regards,

PL.Seenivasan

Feb 6 '06 #1
6 1345
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Seenivasan Palaniappan wrote:
I heard people saying when executing a program 3 standard files will be
opened namely STDIN, STDOUT, STDERR. Is it so? if so what is the
purpose and what each of them stands for?

Explanation of the concept, Guidence to / provision of resources will
be of great help.


"There is a large family of UNIX programs that read some input, perform a
simple transformation on it, and write some output. Examples include grep and
tail to select part of the input, sort to sort it, wc to count it, and so on."
("The Unix Programming Environment" Brian W. Kernighan & Rob Pike)

The designers of Unix decided that there is some utility in providing every
program with predefined access to three data streams. They include access to
an input data stream (called "stdin") that the program can read and process,
an output data stream (called "stdout") that the program can write it's normal
output to, and a second output data stream (called "stderr") that the program
can write error messages or other diagnostics to.

They also provided mechanisms to permit programs to be hooked together in
"pipelines", with the output (that is, stdout) from one program being piped
directly into the input (that is, stdin) of the next program.
- --
Lew Pitcher

Master Codewright & JOAT-in-training | GPG public key available on request
Registered Linux User #112576 (http://counter.li.org/)
Slackware - Because I know what I'm doing.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.7 (GNU/Linux)

iD8DBQFD5t5OagVFX4UWr64RAo7gAKDKaYXL8voVTEdV6HwhWf IaCg3qQwCeK69W
fbXewYWN9NM1ZkMFtgBVUmE=
=mT6d
-----END PGP SIGNATURE-----
Feb 6 '06 #2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Lew Pitcher wrote:
Seenivasan Palaniappan wrote:
I heard people saying when executing a program 3 standard files will be
opened namely STDIN, STDOUT, STDERR. Is it so? if so what is the
purpose and what each of them stands for?

Explanation of the concept, Guidence to / provision of resources will
be of great help.

"There is a large family of UNIX programs that read some input, perform a
simple transformation on it, and write some output. Examples include grep and
tail to select part of the input, sort to sort it, wc to count it, and so on."
("The Unix Programming Environment" Brian W. Kernighan & Rob Pike)

The designers of Unix decided that there is some utility in providing every
program with predefined access to three data streams. They include access to
an input data stream (called "stdin") that the program can read and process,
an output data stream (called "stdout") that the program can write it's normal
output to, and a second output data stream (called "stderr") that the program
can write error messages or other diagnostics to.


I forgot to add that, originally C was developed to support Unix, and so C
natively supported these three streams. Later, C was standardized such that it
no longer focused on Unix, but the three data streams were still useful enough
a concept to remain unchanged in the definition of the language.

[snip]

- --
Lew Pitcher

Master Codewright & JOAT-in-training | GPG public key available on request
Registered Linux User #112576 (http://counter.li.org/)
Slackware - Because I know what I'm doing.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.7 (GNU/Linux)

iD8DBQFD5t7hagVFX4UWr64RAi6AAJ0Ra8BevVEJSexgQozd8s 3EyDB2dwCgqN1+
5JSHzzUN5WaerKVtY0x0IVc=
=Fe9D
-----END PGP SIGNATURE-----
Feb 6 '06 #3
Lew Pitcher wrote:
[... stdin/stdout/stderr ...]
I forgot to add that, originally C was developed to support Unix, and so C
natively supported these three streams. Later, C was standardized such that it
no longer focused on Unix, but the three data streams were still useful enough
a concept to remain unchanged in the definition of the language.


Not to mention the fact that it gives you a portable way to access these
I/O channels if they exist.

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>
Feb 6 '06 #4
On 5 Feb 2006 20:52:37 -0800, "Seenivasan Palaniappan"
<se********************@gmail.com> wrote:
I heard people saying when executing a program 3 standard files will be
opened namely STDIN, STDOUT, STDERR. Is it so? if so what is the
purpose and what each of them stands for?
Yes. Your program is free to use them any way it sees fit. Normally
used for input, "normal" output, and error messages, respectively.

Explanation of the concept, Guidence to / provision of resources will
be of great help.


For concepts, look in your text book. The rest is system specific so
you need to look in the documentation of your system.
Remove del for email
Feb 7 '06 #5
On Mon, 06 Feb 2006 19:14:11 -0800, Barry Schwarz <sc******@doezl.net>
wrote:
On 5 Feb 2006 20:52:37 -0800, "Seenivasan Palaniappan"
<se********************@gmail.com> wrote:
I heard people saying when executing a program 3 standard files will be
opened namely STDIN, STDOUT, STDERR. Is it so? if so what is the
purpose and what each of them stands for?


Yes. Your program is free to use them any way it sees fit. Normally
used for input, "normal" output, and error messages, respectively.

Almost. You aren't portably allowed to do output on STDIN, or input on
STDOUT and STDERR. They aren't guaranteed to be seekable, and on most
systems much of the time aren't, so you can't rely on that.
- David.Thompson1 at worldnet.att.net
Feb 13 '06 #6
Dave Thompson <da*************@worldnet.att.net> wrote:
On Mon, 06 Feb 2006 19:14:11 -0800, Barry Schwarz <sc******@doezl.net>
wrote:
On 5 Feb 2006 20:52:37 -0800, "Seenivasan Palaniappan"
<se********************@gmail.com> wrote:
I heard people saying when executing a program 3 standard files will be
opened namely STDIN, STDOUT, STDERR. Is it so? if so what is the
purpose and what each of them stands for?


Yes. Your program is free to use them any way it sees fit. Normally
used for input, "normal" output, and error messages, respectively.

Almost. You aren't portably allowed to do output on STDIN, or input on
STDOUT and STDERR. They aren't guaranteed to be seekable, and on most
systems much of the time aren't, so you can't rely on that.


However, if you _do_ manage to freopen() one of them in read-and-write
mode, you are free to do so. Success of freopen() is checkable.
Unfortunately, doing this to std*, of which you don't (portably) know
the original file name (if they have one at all) requires a null pointer
for the first argument to freopen(), which requires C99.

So yes, your program is free to _try_ and use them as it sees fit - but
you're neither guaranteed to have the means to do so, nor even that
you'll succeed in your attempt if you do.

Richard
Feb 13 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

71 posts views Thread by Christopher Benson-Manica | last post: by
1 post views Thread by Tim Slattery | last post: by
43 posts views Thread by Steven T. Hatton | last post: by
5 posts views Thread by jayceechong | last post: by
16 posts views Thread by Spiros Bousbouras | last post: by
270 posts views Thread by jacob navia | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.