472,956 Members | 2,252 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,956 software developers and data experts.

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 1480
-----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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: FISH | last post by:
Ever have one of those days when you're not sure if it's you who's gone mad, or the rest of the world? I have an Open Source project on SourceForge for communication with YSMG - Yahoo's IM...
1
by: Corrie Meyer | last post by:
Announcement: SwiftReports standard edition 1.0 for Visual Studio ..NET 2003 released by UniSwift. We are pleased to announce the first release of a fully-managed reporting tool for the...
3
by: Asfand Yar Qazi | last post by:
Hi, Here's the thing: the Eternity persistence system does not provide its own compilation phase for its source code: the programmer simply has to copy some files to his codebase. Here's the...
71
by: Christopher Benson-Manica | last post by:
At what point was the .h dropped from the STL headers? I just had a discussion yesterday with my boss, who said he wanted .h on all the STL includes, despite me protesting that it was not...
1
by: Tim Slattery | last post by:
Does the C++ language standard mandate a particular name-mangling method? I'm trying to use the Entrust toolkit to create a C++ program that encrypts and decrypts files. Entrust supplies header...
43
by: Steven T. Hatton | last post by:
Now that I have a better grasp of the scope and capabilities of the C++ Standard Library, I understand that products such as Qt actually provide much of the same functionality through their own...
16
by: ben beroukhim | last post by:
I have huge number of legacy code which use standard files functions. I would like to pass a memory pointer rather than a FILE pointer. I am trying to use FILEs in the code to refer to memory...
5
by: jayceechong | last post by:
If I write my own C compiler, can I just "take" existing standard header files (e.g. stdio.h, stdlib.h, etc.) from an existing C compiler and plug them in my own? I understand I have to write my...
16
by: Spiros Bousbouras | last post by:
There are several compilers which accept various extensions to the C language and produce native code. But I wonder if there are any which offer the option to translate from C with some extensions...
270
by: jacob navia | last post by:
In my "Happy Christmas" message, I proposed a function to read a file into a RAM buffer and return that buffer or NULL if the file doesn't exist or some other error is found. It is interesting...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.