🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.msdos.programmer
Article #1148

Detecting DOS redirection requests.

#1148
From: David B. Ferguson
Date: Mon, 04 Sep 1995 02:20
88 lines
3322 bytes
 Thanks to all that responded to my request for DOS redirection request
detection.  We wanted to do this for a little utility that we're writing
and wanted to be able to tell if the operator was redirecting the programs
stdout to a file or printer and thus reformat the output accordingly and
acknowledge the operator that the program was doing so, and also removing
the "Press any key to continue..." like prompt as well for the second screen
of data output.

 We had lot's of replies, anly one sort of worked, but had some obvious
inherent problems.  Others were creative but not practical, one looked
like the formula to get C to split an atom, I didn't dare compile that one.

 The responces did however get us thinking and pointed in the right 
direction and this is the end result.


/*

   DIRECTIN.C - Sample code to test for DOS redirection requests
   David B. Ferguson
   Saturday Sept 2, 1995

   DIRECTIN > TEST.TXT    result   Redirection has been requested.

   DIRECTIN               result   Redirection hasn't been requested.

*/


#include <stdio.h>
#include <dos.h>


int main(void)
{

    fprintf(stderr, "\n  Redirection has%s been requested.\n",
      redirected(stdout) ? "n't" : "");

    return(0);
}


int redirected(FILE *fp)
{
   union REGS regs;

   regs.x.ax = 0x4400;
   regs.x.bx = (unsigned)fileno(fp);
   intdos(&regs, &regs);

   if (0 == (regs.x.ax & 0x80))
     return 0;

   return (!(!(regs.x.ax & 0x13)));

}

/* End of file DIRECTIN.C */


 So there it is for all those that said it wan't possible, and those
that may need to do this in the future, this just might save you from
wiping your city of the map. :-)


BTW - My appoligies to those that pointed out my inappropriate
      group posting, and yes I know I'm doing it again.

Regards,

David-
                                     O
                                    o                   
                            |||||  o                    
                            -   -     
                          @(0)-(0)@                     
---------------------oOOO-----U-----OOOo-------------------------------------  
    David B. Ferguson                    Internet....: microtsk@fox.nstn.ca
    Consultant                           Voice.......: (902)464-9976  
    MicroTask                            Pager.......: (902)459-2697
    Computer Services                    Address.....: 8 Faulkner St.
                                                       Dartmouth, N.S.
                                                       Canada, B3A 3A3
-----------------------------------------------------------------------------
          Programmer - an organism that turns coffee into software
-----------------------------------------------------------------------------
Technical Details
Message-ID: <89890.microtsk@fox.nstn.ca>
Path: arc1-ca.pugleaf.net!nstn.ns.ca!news

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!nstn.ns.ca!news
From: "David B. Ferguson" <microtsk@fox.nstn.ca>
Newsgroups: alt.msdos.programmer,comp.lang.c,comp.os.msdos.programmer
Subject: Detecting DOS redirection requests.
Date: Sun, 3 Sep 95 22:20:35 -0400
Organization: Nova Scotia Technology Network
Message-ID: <89890.microtsk@fox.nstn.ca>
Reply-To: <microtsk@fox.nstn.ca>
NNTP-Posting-Host: halifax-ts1-62.nstn.ca
X-Minuet-Version: Minuet1.0_Beta_14.1
X-POPMail-Charset: English