Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!ginosko!uunet!zephyr!tektronix!tekcrl!tekgvs!toma From: toma@tekgvs.LABS.TEK.COM (Tom Almy) Newsgroups: comp.sys.ibm.pc Subject: Re: MS-DOS puzzle #1 Message-ID: <5565@tekgvs.LABS.TEK.COM> Date: 13 Jul 89 15:03:55 GMT References: <8167@bsu-cs.bsu.edu> <1171@calvin.EE.CORNELL.EDU> <5486@pt.cs.cmu.edu> Reply-To: toma@tekgvs.LABS.TEK.COM (Tom Almy) Distribution: comp Organization: Tektronix, Inc., Beaverton, OR. Lines: 29 In article <5486@pt.cs.cmu.edu> ralf@b.gp.cs.cmu.edu (Ralf Brown) writes: >What can be done, however, (and this works for DOS 2 and up), is to copy the >appropriate entries in the Process File Table in the PSP, zap them to FFh >(unused), do the EXEC, and then restore the entries. While the child will >then get the same handle number on opening a file, it will refer to a >different file (the above is what the no-inherit attribute does, anyway--it >zaps the uninheritable handles in the child's PFT to FFh). Right on! I was working on a large programming environment that needed to EXEC arbitrary programs (or a DOS shell), with the ability to redirect stdin, stdout, and stderr. I did a variation of Ralf's scheme: 1. Save entire PFT (it's not that big!) 2. Set entries above the std* ones to FFh (effectively temprarily closes my programs files, without DOS overhead, but requiring a larger FILES= spec in config.sys). 3. Set to 0FFh and then open each redirected std*, one at a time. Since the open command uses the lowest numbered free descriptor, this works well. 4. EXEC the program 5. Do a close on each redirected std*. 6. Restore PFT from saved copy. Was that easy enough? Much simpler than the contortions in UNIX with those DUP2s! There certainly is no reason COMMAND.COM couldn't do it. And fork() has nothing to do with it. Tom Almy toma@tekgvs.labs.tek.com Standard Disclaimers Apply