Thread View: alt.msdos.programmer
2 messages
2 total messages
Started by Tim Ma
Fri, 13 Nov 1992 01:14
Dos redirection
Author: Tim Ma
Date: Fri, 13 Nov 1992 01:14
Date: Fri, 13 Nov 1992 01:14
13 lines
729 bytes
729 bytes
This may be a pretty easy question (it seems like it might be), but the answer eludes me. Is there anyone I can tell from within a C program whether the user has redirected the output to a file using DOS redirection (>)? Thanks, Tim Ma Associate Programmer University of Utah Email: tim@src.cppa.utah.edu
Re: Dos redirection
Author: 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. |
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads