Mail Archives: djgpp/1999/08/15/11:00:54
On Fri, 13 Aug 1999, Edevaldo Pereira da Silva Junior wrote:
> I was thinking about using dup & dup2 to make the stderr point to a
> tempfile then call "prog.exe" with system or popen. What I do not know
> is how to make the stderr point to the right place again once the
> prog.exe has finished. Any suggestions?
The same as above: with dup and dup2. You use dup to save the original
stderr in a variable, then, when the child program exits, use dup2 to
force stderr to point to the same handle as the one you saved with dup.
For examples of how this is done, look in the sources of `system' and
`popen' in the DJGPP library. They do it for stdout, not stderr, but
this difference is not important.
> Another question: Regarding file descriptors, is it usual that the
> descriptors 0,1 & 2 will always point to stdin,stdout & stderr
> respectively?
I believe this is Posix-standard, but I'm not sure.
> Is it standard across platforms?
I'd guess that many C programs would be badly broken if this was not the
case.
However, you shouldn't usually need to rely on this.
- Raw text -