Solved

stdout and stderr in Linux

Posted on 1998-04-28
4
1,953 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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

622 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