🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.msdos.programmer
Article #1149

Re: Detecting DOS redirection requests.

#1149
From: Steffen Kaiser
Date: Mon, 04 Sep 1995 02:03
31 lines
2050 bytes
On 3 Sep 1995, Henk den Adel wrote:

> : "David B. Ferguson" <microtsk@fox.nstn.ca> wrote:
> : -> How does one tell the user has requested DOS redirection from within
> : ->his application. Using C BTW. 
> : 	in all cases of command line line redirection, the file assignments
> : are changed by the shell, not by the program. The program does not
> : know where its input comes from nor where its output goes, so long as
> : it uses file 0 for input and 1 and 2 for output. See K&R (2nd edition)
> : 7.1 and 8.1 for further details.

If you want to know, whether your program has been redirected into (or from)
a file, you can use:
stdinRedirectedToFile = !isatty(fileno(stdin));
stdoutRedirectedToFile = !isatty(fileno(stdout));
	Note: "program >nul", "program >com1" will be considered as to
		be connected to TTYs, because all character devices are
		"valid" TTYs.

If you want to know, whether your program is connected to the console,
you must use:
stdinOnCON = (ioctl(fileno(stdin), 0) & 0x81) == 0x81;
stdoutOnCON = (ioctl(fileno(stdout), 0) & 0x82) == 0x82;

Unfortunately you cannot (easily) detect, whether or not the shell's
console has been changed by the "stty" command. So after a "stty COM1",
the ioctl() will tell you, that stdin is not connected to a console and
isatty() will tell, that stdin is a console.
--

Steffen
Technical Details
Message-ID: <Pine.LNX.3.91.950904035021.80A-100000@egal.csn.tu-chemnitz.de>
Path: arc1-ca.pugleaf.net!egal.csn.tu-chemnitz.de!ska
References: <92011.microtsk@fox.nstn.ca> <42bg3q$dr0@ixnews6.ix.netcom.com> <42cu2b$dk4@mo6.rc.tudelft.nl>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!egal.csn.tu-chemnitz.de!ska
From: Steffen Kaiser <ska@informatik.tu-chemnitz.de>
Newsgroups: alt.msdos.programmer,comp.lang.c,comp.os.msdos.programmer
Subject: Re: Detecting DOS redirection requests.
Date: Mon, 4 Sep 1995 04:03:46 +0200
Organization: University of Technology Chemnitz, FRG
Message-ID: <Pine.LNX.3.91.950904035021.80A-100000@egal.csn.tu-chemnitz.de>
References: <92011.microtsk@fox.nstn.ca> <42bg3q$dr0@ixnews6.ix.netcom.com> <42cu2b$dk4@mo6.rc.tudelft.nl>
NNTP-Posting-Host: egal.csn.tu-chemnitz.de
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
X-Sender: ska@egal.csn.tu-chemnitz.de
In-Reply-To: <42cu2b$dk4@mo6.rc.tudelft.nl>