473,497 Members | 2,041 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

are stdout and stderr different

For example, in Bourne Shell both stdout and stderr can be re-directed
to /dev/null,

$ ./a.out 2>&1 /dev/null

then is there any difference still?
Jun 29 '08 #1
4 2277

"lovecreatesbea...@gmail.com" <lo***************@gmail.comwrote in message
news:
For example, in Bourne Shell both stdout and stderr can be re-directed
to /dev/null,

$ ./a.out 2>&1 /dev/null

then is there any difference still?
Not then. Let's say we direct to a file rather than /dev/null. By examining
the file, we cannot tell whether a particular line came from stdout or
stderr.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Jun 29 '08 #2
lovecreatesbea...@gmail.com wrote:
For example, in Bourne Shell both stdout and stderr can be re-directed
to /dev/null,

$ ./a.out 2>&1 /dev/null

then is there any difference still?
It's customary for stderr to be unbuffered while stdout is usually line
buffered or fully buffered. These properties can of course be changed
from within the program by using setvbuf.

Jun 29 '08 #3
On Jun 29, 1:11 pm, santosh <santosh....@gmail.comwrote:
lovecreatesbea...@gmail.com wrote:
For example, in Bourne Shell both stdout and stderr can be re-directed
to /dev/null,
$ ./a.out 2>&1 /dev/null
then is there any difference still?

It's customary for stderr to be unbuffered while stdout is usually line
buffered or fully buffered. These properties can of course be changed
from within the program by using setvbuf.
Note that the buffer supplied to setvbuf() needs to have a lifetime at
least as much as the file stream.
The contents of the buffer are indeterminate. (n1256 - 7.19.5.6 p2)

stdin is also an input stream, while stdout and stderr are output
streams.
That can also be changed from within the program with 'freopen', and
it's in fact the most common usage of the function.
'stdin, 'stdout', 'stderr' need not to be modifiable lvalues.
fclose(stdout); /* so far so good */
stdout = fopen("helloworld", "w"); /* bad */

Imagine this case:

#define stdout __stream(1)
inline FILE *__stream(size_t i) { return __file[i]; }

stdout = fopen("helloworld", "w"); /* constraint violation, requires
diagnostic by the compiler */

A common mistake is to flush stdin, 'fflush(stdin)' which invokes
undefined behavior.
'stdin' doesn't need to be flushed. "flushing" input streams doesn't
make sense. Typically one wants to read until a newline or EOF is met
and discard those characters, which could be written as:

int foo(FILE *stream) { int c; while((c = getc(stream)) != EOF && c !=
'\n'); return c; }

The standard doesn't mention what kind of files 'stdin', 'stdout',
'stderr' are. In fact, the standard does not require these to be valid
files. (not *file streams* - they do need to be valid file streams)
It could be that all file operations on these three predefined streams
failed, however I'm not aware of such implementation.
The programmer needs not to know what kind of files they are either;
Just perform the normal checking of the file functions.
(offtopic: with a standard like POSIX it's also possible to see the
value of errno for more information on *why* the operation failed, ISO
C99 defines only three macros, EDOM, EILSEQ, ERANGE which are not
relevant to file operations. 7.5 p2. Try comp.unix.programmer if you
are interested to learn about POSIX)
Jun 29 '08 #4
In article <Pa******************************@bt.com>,
Malcolm McLean <re*******@btinternet.comwrote:
>
"lovecreatesbea...@gmail.com" <lo***************@gmail.comwrote in message
news:
>For example, in Bourne Shell both stdout and stderr can be re-directed
to /dev/null,

$ ./a.out 2>&1 /dev/null

then is there any difference still?
Not then. Let's say we direct to a file rather than /dev/null. By examining
the file, we cannot tell whether a particular line came from stdout or
stderr.
Keep in mind that the above command (when run on a POSIX system, which
makes this all OT in clc - heh heh - do I get the "first one to say OT
points" here?) runs the "a.out" command, passing the string "/dev/null"
as a parameter (argv[1] value in the program) and with stderr pointing
to the same file descriptor as stdout (presumably, the terminal).

It doesn't look like anything is being redirected to /dev/null
(although, of course, the program could do that inside, using, e.g., freopen())

Jun 29 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
5607
by: Tsai Li Ming | last post by:
Dear all, I have a problem with a redirecting stdout and stderr. I am a top level module and has no control over the imported modules that are making system calls such as os.system or popen2.* ....
3
3731
by: David Douard | last post by:
Hi everybody, let me explain by problem: I am working on an application which consists in a C++ dll (numeric computations) and a Python IHM (Python/Tk), which must run under Linux and win32. My...
3
3411
by: Laszlo Zsolt Nagy | last post by:
Hello, I have this code: s = smtplib.SMTP() s.set_debuglevel(1) s.connect(host=smtp_host) s.set_debuglevel(0) log("Connected, sending e-mail") sys.stdout.flush()
7
11603
by: Andre | last post by:
Hi, I have a program that sends some output to stdout and some to stderr. I need to separate the two using the command-line so that I direct stderr output to a file, say fileA.txt, and stdout...
37
5010
by: nobody | last post by:
I am writing a framework that other developers will write plug-ins for. I would like for one of the features of the framework to be to intercept all text written to stdout/stderr and prepend...
0
2416
by: Christoph Haas | last post by:
Evening, I'm having trouble with running a process through Python 2.4's subprocess module. Example code: ======================================================== def run(command): run =...
10
7601
by: SamG | last post by:
How could i make, from inside the program, to have the stdout and stderr to be printed both to a file as well the terminal(as usual).
1
3755
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
Hello, I have a C# application in which I start another process which produces output to stdout and stderr. In fact, that process is the uSoft VS2005 C/C++ compiler itself! I would like to...
2
8440
by: Guillaume Dargaud | last post by:
Hello all, a while ago I was pointed towards freopen as a way to redirect stderr to a log file. It works great, but apparently the app also writes a few lines to stdout. Now I could redirect to 2...
0
7121
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6993
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7162
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7197
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6881
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4899
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1411
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.