delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/10/07/08:42:54

Date: Tue, 7 Oct 1997 14:41:23 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Jose Luis Perandones Colino <joepc AT writeme DOT com>
cc: djgpp AT delorie DOT com
Subject: Re: Correct redirection
In-Reply-To: <3.0.32.19971003105005.0068b970@mail.santandersupernet.com>
Message-ID: <Pine.SUN.3.91.971007144104.25685K-100000@is>
MIME-Version: 1.0

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.

- Raw text -


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