Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site watcgl.UUCP Path: utzoo!watmath!watcgl!jchapman From: jchapman@watcgl.UUCP (john chapman) Newsgroups: net.micro.pc Subject: Re: More on the EXEC function call Message-ID: <1275@watcgl.UUCP> Date: Fri, 15-Feb-85 12:19:22 EST Article-I.D.: watcgl.1275 Posted: Fri Feb 15 12:19:22 1985 Date-Received: Sat, 16-Feb-85 05:49:39 EST References: <243@shell.UUCP> Organization: U of Waterloo, Ontario Lines: 62 > I am writing a program which must be able to execute another > program from within my program, based upon a user supplied > command. > > Using DOS function 4B works fine. For a while, I was merely > using it to invoke a second copy of COMMAND.COM (god, I wish > MicroSoft had seperated the code & data segments so this wasn't > necessary). Anyhow, if I use function 4B to invoke a second > COMMAND.COM, my specified command can use redirection. > > BUT, I decided I would try to eliminate the overhead of loading > COMMAND.COM when a program was being invoked. Well, suprise! If > you run function 4B to load a program which has redirection on > the command line, it doesn't work! > > Could someone please tell me how I can inform DOS apriori that I > wish all standard output (or input) to be redirected? Is IOCTL the > way to go? If so, how is it done? > > Any help would be much appreciated. Thanks. > > Bob Starr @ Shell Development I too was wanting to redirect io for an invoked command; this was mentioned in only one place in my MS-DOS documentation something to the effect "you can change the definition of stdin & stdout and then invoke a program, this is extremely powerful" and then no mention anywhere of how to do it. Anyway after a while I figured it out (I think - I have only done minor testing but it seems to work the way you would expect); I'm doing this from memory so I can't give you the function numbers but they are in the doc. Sooo, if you want to redirect stdin to file XXX do something like the following: 1. open a file handle to XXX 2. do a force duplicate file handle (force duplicate not just duplicate file handle), setting cx=1 just before. For this call cx is the number of the new file handle to be the duplicate. 3. close the original file handle to XXX 4. EXEC your program. The mapping of handles to devices seems to be: Handle Device/File 1 stdin 2 stdout 3 auxin 4 auxout 5 stdlst Some points to note: 1. this requires a free file handle to do plus the five handles above so your config.sys FILES=n should have n=6+number of other simultaneously open files 2. this affects not only i/o from the handles 1-5 but the device specific function calls to con:,prn: etc (functions 1-9). Hope this is what you wanted! John Chapman ...!watmath!watcgl!jchapman