Date: Tue, 7 Oct 1997 14:41:23 +0200 (IST) From: Eli Zaretskii To: Jose Luis Perandones Colino cc: djgpp AT delorie DOT com Subject: Re: Correct redirection In-Reply-To: <3.0.32.19971003105005.0068b970@mail.santandersupernet.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk On Mon, 6 Oct 1997, Jose Luis Perandones Colino wrote: > But if i use the standar output i don't redirect the output of my > program ( i can't use myprogram.exe > out.txt ) becasuse it lost. You are reinventing the wheel, and it comes out square. The DJGPP library has `popen' and `pclose' functions that are intended for such cases. Your best bet is to use them. The problem in your code is that you didn't save the original stdout before calling `dup2'. You should save it with a call to `dup'. Then, after the child program returns, restore stdout by calling `dup2' and using the saved stdout file handle. But as I said, using `popen' is the way to go, since it already does that correctly.