delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/11/03/01:35:24

From: Weiqi Gao <weiqigao AT a DOT crl DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: redirecting stdout from within a DJGPP program
Date: Tue, 03 Nov 1998 00:33:01 -0600
Organization: CRL Network Services
Lines: 21
Message-ID: <363EA39D.4D6A43C8@a.crl.com>
References: <363e9c11 DOT 35648820 AT news DOT cis DOT yale DOT edu>
NNTP-Posting-Host: a116023.stl1.as.crl.com
Mime-Version: 1.0
X-Mailer: Mozilla 4.5 [en] (X11; I; Linux 2.0.32 i586)
X-Accept-Language: en
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Mapson wrote:
> 
> There is one point in my program where I call another program (using
> system("program.exe") ), and I am interested in redirecting (and
> silencing at the console) the output of that program to a file I
> already have opened for output. This is something I'd previously done
> in a batch file with ">>"
> 
> freopen() basically works, but it doesn't silence the output to the
> console. Is there a better way?

A non-standard way is to do a:
  int fd;
  close(1);
  fd = open("yourfile", O_WRONLY | O_CREAT | O_APPEND);
on start up of your program.  That way fd will be 1, which is stdout to
most programs.

-- 
Weiqi Gao
weiqigao AT a DOT crl DOT com

- Raw text -


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