Redirecting stdout, and then getting it back
Taed Nelson
nelson at berlioz.nsc.com
Sat Feb 16 02:38:58 AEST 1991
In article <15202 at smoke.brl.mil> gwyn at smoke.brl.mil (Doug Gwyn) writes:
>In article <1991Feb14.035930.20173 at berlioz.nsc.com> nelson at berlioz.nsc.com (Taed Nelson) writes:
>>We have a "shell" program which executes programs from within it using the
>> system()/spawn() call. We wanted to trap these errors, so we freopen()ed
>
>You were lucky. The UNIX convention is that file descriptors 0, 1, and 2
>are the standard I/O/error hooks. While in a given stdio-using program
Actually, we weren't "lucky" -- the man page for freopen() says that this
is a common use of the command.
Thanks for the replies. What I didn't make clear enough is that we operate
under both DOS and Unix; I thought the REAL solution would be applicable
to both. Clearly, I forgot about fork() and did not think of using it
due to the DOS environment.
Our final solution, which works, is to do another freopen() before going
to the shell which redirects stdout and stderr back to "CON". I was
really happy that that little tidbit was not documented in the manual
(actually, pissed off is a more appropriate adjective). I wonder how one
would actually open a file named "CON"?
More information about the Comp.unix.questions
mailing list