Article View: alt.msdos.programmer
Article #751Re: Dos redirection
From: Carl Harris
Date: Sun, 15 Nov 1992 15:03
Date: Sun, 15 Nov 1992 15:03
49 lines
2410 bytes
2410 bytes
tim@tim.src.utah.edu (Tim Ma) writes: : : Is there anyone I can tell from within a C program whether the user has : redirected the output to a file using DOS redirection (>)? : Use the ioctl and fileno functions to get the device/file parameters from DOS. For standard input, use stdinparms = ioctl(fileno(stdin),0); Substitute 'stdout' for 'stdin' to get the same data for standard output. The return value will have bit 7 = 0 if the handle associated with the stream you pass to fileno is a device, or bit 7 = 1 if it's a file. e.g. to determine if stdin refers to a file, use something like isredirected = ioctl(fileno(stdin),0) & 0x0080; The above example will determine when stdin has been redirected to a file. To determine when standard input or output has been redirected to a device other than CON, you can examine the lower 3 bits of the ioctl return value. When bit 7 = 0 (indicating that the handle refers to a device), the values of the low order bits are bit 0: 1 if handle refers standard input device (CON) bit 1: 1 if handle refers standard output device (CON) bit 2: 1 if handle refers to null device (NUL) For example, to determine if stdout has been redirected to a some other device (LPT1, AUX, etc.), assuming bit 7 is zero, use isotherdevice = !(ioctl(fileno(stdout),0) & 0x0001); Note that you can determine only that the device is not CON (i.e. you can't determine what device the handle actually refers to). Bit 2 is especially useful if you don't wish to waste time writing output to the NUL device. Hope this helps! Write me, e-mail, if you have more specific questions about this. Carl Harris ceharris@csugrad.cs.vt.edu -- +---------------+---------------------------------------------------+ | Carl Harris |program (tv). To engage in an activity similar to | | CS @ VA TECH |banging one's head against a wall, but with fewer | | |opportunities for reward. |
Technical Details
Message-ID:
<BxrJ5o.AHq@csugrad.cs.vt.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!vtserf!csugrad!ceharrisReferences:
<tim.8.721617288@tim.src.utah.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!vtserf!csugrad!ceharris From: ceharris@csugrad.cs.vt.edu (Carl Harris) Newsgroups: alt.msdos.programmer Subject: Re: Dos redirection Message-ID: <BxrJ5o.AHq@csugrad.cs.vt.edu> Date: 15 Nov 92 15:03:23 GMT References: <tim.8.721617288@tim.src.utah.edu> Organization: Virginia Tech Computer Science Dept, Blacksburg, VA Lines: 49 X-Newsreader: Tin 1.1 PL4