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
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"
stderr=fopen("/dev/stderr"
Anyway, how can I achieve it ?
Andrew
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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!
Hope you did not mean to do that!
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.