Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

stdout and stderr in Linux

Posted on 1998-04-28
4
Medium Priority
?
1,965 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 2

Accepted Solution

by:
seedy earned 0 total points
ID: 1292544
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
ID: 1292545
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
ID: 1292546
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
ID: 1292547
Sinu,
Hope you did not mean to do that!
0

Featured Post

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

715 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