🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #5843

Re: Sensing STDOUT redirection in C

#5843
From: Zack C. Sessions
Date: Thu, 18 Apr 1991 17:41
29 lines
1929 bytes
collinsa@p4.cs.man.ac.uk (Adrian Collins) writes:

>I am currently writing a program for the PC using C.  I need to be able
>to sense whether STDOUT has been redirected on the command line.  In the
>case where the output has not been redirected the program opens a text
>window and displays the info in that window, but if output redirection
>was used I want the program to output to STDOUT as it should assume that
>the output is to be sent to a file.

>Does anybody know how to sense whether output redirection has been used
>on the command line?

Even though I have the Power C for MS-DOS (you didn't mention which
one you are using) I use it very seldom. I do most of my C programming
with the Microware C Compiler for OS-9 Level 2. With it you can tell
the difference by using a system call which returns the name of the
device which a path is opened up to. There are only certain types of
devices which are window devices and disk devices. If the STDOUT
path is a window device, it has not been re-directed (normally)
and if it is a disk device it definitely has been re-direected. Some
others here may flame you (and me) for posting such information
on a discussion on "pure C" topics and to machine or OS dependent
type questions and answers.

If there is some portable valid method for doing this type of operation,
I'd certainly be interested in hearing about it.

Zack Sessions
session@seq.uncwil.edu
Technical Details
Message-ID: <1379@seq.uncwil.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!emory!gatech!mcnc!ecsgate!seq!session
References: <collinsa.671721083@p4.cs.man.ac.uk>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!emory!gatech!mcnc!ecsgate!seq!session
From: session@seq.uncwil.edu (Zack C. Sessions)
Newsgroups: comp.os.msdos.programmer
Subject: Re: Sensing STDOUT redirection in C
Keywords: STDOUT, Redirection, MSDOS
Message-ID: <1379@seq.uncwil.edu>
Date: 18 Apr 91 17:41:24 GMT
References: <collinsa.671721083@p4.cs.man.ac.uk>
Organization: Univ. of North Carolina @ Wilmington
Lines: 29