delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/08/15/11:00:54

Date: Sun, 15 Aug 1999 12:54:57 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: Edevaldo Pereira da Silva Junior <Edevaldo DOT Pereira AT motorola DOT com>
cc: djgpp AT delorie DOT com
Subject: Re: TCL Port to DJGPP - Bug + Advices.
In-Reply-To: <37B4186B.9344D7CC@motorola.com>
Message-ID: <Pine.SUN.3.91.990815125101.1935V-100000@is>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019