🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.msdos.programmer
Article #1153

Re: Formulated unclear : Re: Redirection of STDERR ??

#1153
From: Dusty Reichwein
Date: Sat, 18 Nov 1995 05:20
53 lines
2041 bytes
Fred.Dullemond@Austria.ATTGIS.COM (Fred (Frot)) wrote:

>Fred.Dullemond@Austria.ATTGIS.COM (Fred (Frot)) wrote:

[snip]
>So I need some C-CODE which allows me to redirect the stderr &| stdout
>to something else.

>Fred

To do this you will need to use file handle functions instead of the
standard C functions.  On the compiliers I'm used to the functions
needed are called open() and close() and are declared in dos.h
(consult your compilier manual for details).

To redirect stdin, stdout, or stderr to a file called myfile do
something like this:
--- start psuedocode
  int handle, handle2, handle 3;

  /* redirect standard file handle */  
  handle2 = open("myfile", /*permission flags etc */ );
  
   dup2(handle2, handle);   
  /* handle should be
      0 for stdin,
      1 for stdout,
      2 for stderr,
      3 for stdaux
      and 4 for stdprn  
      The old  file referenced by handle is closed if neccessary
       I don't know if dup2 is supported by M$ compiliers*/

     /* exec program */

     /* restore standard file handle */

      handle3 = open(newfile, /*permission flags */);  
      /* new file should be "CON" for the screen, "AUX"  for

         auxilliary, PRN for printer */

       dup2(handle3, handle);
---end psuedocode

    I just wrote this on the fly, so there could be some problems with
it,  but I'm pretty sure this is the way to redirect  stdin, stdout,
etc.  

    Good Luck!

Dusty Reichwein
reichwej@ucs.orst.edu
Technical Details
Message-ID: <48jq6u$a9b@news.orst.edu>
Path: arc1-ca.pugleaf.net!news.orst.edu!news
References: <DI3BnA.JF5@news.zippo.com> <DI50nF.AwH@news.zippo.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.orst.edu!news
From: reichwej@ucs.orst.edu (Dusty Reichwein)
Newsgroups: alt.msdos.programmer,comp.lang.c,comp.msdos.programmer,comp.os.msdos.programmer
Subject: Re: Formulated unclear : Re: Redirection of STDERR ??
Date: Sat, 18 Nov 1995 05:20:20 GMT
Organization: University Computing Services - Oregon State University
Message-ID: <48jq6u$a9b@news.orst.edu>
References: <DI3BnA.JF5@news.zippo.com> <DI50nF.AwH@news.zippo.com>
NNTP-Posting-Host: slip60.ucs.orst.edu
X-Newsreader: Forte Free Agent 1.0.82