Link to home
Start Free TrialLog in
Avatar of andrewyu
andrewyu

asked on

stdout and stderr in Linux

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
ASKER CERTIFIED SOLUTION
Avatar of seedy
seedy

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of seedy
seedy

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.
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.
Sinu,
Hope you did not mean to do that!