home *** CD-ROM | disk | FTP | other *** search
- From: Jerry Coffin
- To: All Date: 15 Dec 91 12:15:04
- Subj: file redirection
- Conf: `PC Assembly Language'
-
- A while back, someone posted a message about whether you would
- accurately detect redirection of standard input and/or output by testing
- whether file handle(s) 0 & 1 were equal to file handle 3. I've done a
- little testing and found that if you redirect standard error within a
- program, ( freopen() it, for instance. ) and spawn a child program, the
- child's file handle 3 will indeed be changed, and handles 0 and 1 will
- not equal it unless they have redirected to the same file. It would
- appear, therefore, that accurately determining whether input or output
- has been redirected requires using DOS function 52h to find the
- system file table, and tracking through it to find whether the file
- associated with the handle in question is actually connected to a file
- named CON. ( PLEASE prove me wrong on this, though. )
- Later,
- Jerry.
-
- From: Robert Mashlan
- To: Jerry Coffin Date: 16 Dec 91 22:48:15
- Subj: file redirection
- Conf: `PC Assembly Language'
-
- > appear, therefore, that accurately determining whether
- > input or output has been redirected requires using DOS
- > function 52h to find the system file table, and
- > tracking through it to find whether the file
- > associated with the handle in question is actually
- > connected to a file named CON. ( PLEASE prove me
- > wrong on this, though. )
-
- Instead of using an undocumented function, why not use a documented one? Int
- 21h, func 44h, subfunc 0, should give you the information needed.
-
- Robert
-
- From: Ed Beroset
- To: Jerry Coffin Date: 17 Dec 91 08:55:00
- Subj: file redirection
- Conf: `PC Assembly Language'
-
- JC> A while back, someone posted a message about whether you would
- JC> accurately detect redirection of standard input and/or output by testing
- JC> whether file handle(s) 0 & 1 were equal to file handle 3.
-
- There were several messages; I posted one of them.
-
- JC> I've done a
- JC> little testing and found that if you redirect standard error within a
- JC> program, ( freopen() it, for instance. ) and spawn a child program, the
- JC> child's file handle 3 will indeed be changed, and handles 0 and 1 will
- JC> not equal it unless they have redirected to the same file.
-
- This is quite correct. The program I posted was only designed to check for
- command line redirection, and will not detect such subterfuge as you describe.
-
- JC> It would
- JC> appear, therefore, that accurately determining whether input or output
- JC> has been redirected requires using DOS function 52h to find the
- JC> system file table, and tracking through it to find whether the file
- JC> associated with the handle in question is actually connected to a file
- JC> named CON. ( PLEASE prove me wrong on this, though. )
-
- I hadn't considered a program quite this thorough, but it sounds workable. The
- only problem that I see with this strategem is that the console device itself
- may legitimately have been redirected (e.g. CTTY COM1) to a terminal or some
- other device. Let us all know if you work it all out -- sounds interesting!
-
- -> Ed <-
-
- From: Bob Jarvis
- To: Jerry Coffin Date: 17 Dec 91 21:53:34
- Subj: file redirection
- Conf: `PC Assembly Language'
-
- In a message of <15 Dec 91 12:15:04>, Jerry Coffin (1:128/60) writes:
- >not equal it unless they have redirected to the same file. It would
- >appear, therefore, that accurately determining whether input or output
- >has been redirected requires using DOS function 52h to find the
- >system file table, and tracking through it to find whether the file
- >associated with the handle in question is actually connected to a file
- >named CON. ( PLEASE prove me wrong on this, though. )
-
- Perhaps the following code will help:
-
- [extracted to isconsol.c]
-
- Hope this helps.
-
- --- msged 1.99S ZTC
- * Origin: Point of No Return - Westlake OH (1:157/200.26)