Solved

stdout and stderr in Linux

Posted on 1998-04-28
4
1,923 Views
Last Modified: 2013-12-26
UNIXer,

Can I redirect the stdout and stderr to a temporary file by the following code ?
  filename=tmpnam(0);
  freopen(filename, "w", stderr);
  freopen(filename, "w", stdout);

But, how come I cannot print characters to the original stdout and stderr by doing the following code ?
  stdout=fopen("/dev/stdout", "w");
  stderr=fopen("/dev/stderr", "w");

Anyway, how can I achieve it ?

Andrew
0
Comment
Question by:andrewyu
  • 3
4 Comments
 
LVL 2

Accepted Solution

by:
seedy earned 0 total points
Comment Utility
By default stdin and stdout will be pointing to the terminal.
So, when you want to restore them, you would do
   stdout = fopen("/dev/tty", "w");
   stderr = fopen("/dev/tty", "w");
Hope this helps.
PS: Andrewyu, why is that you never grade answers?
   
0
 
LVL 2

Expert Comment

by:seedy
Comment Utility
BTW, there is no device like '/dev/stdout' or '/dev/stderr'.
From man pages for 'tty':
The file '/dev/tty' is, in each process, a synonym for the
control terminal associated with the process group of that
process, if any.
0
 

Expert Comment

by:sinu
Comment Utility
Go thru a good book on unix file io.

 there is no device like '/dev/stdout' or '/dev/stderr'.
From man pages for 'tty':
The file '/dev/tty' is, in each process, a synonym for the
control terminal associated with the process group of that
process, if any.
0
 
LVL 2

Expert Comment

by:seedy
Comment Utility
Sinu,
Hope you did not mean to do that!
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now