Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!cs.utexas.edu!sun-barr!apple!oliveb!pyramid!hplabs!hp-sdd!megatek!zeta!hollen From: hollen@zeta.megatek.uucp (Dion Hollenbeck) Newsgroups: comp.sys.ibm.pc Subject: Re: Executing .BAT files Message-ID: <584@megatek.UUCP> Date: 19 Jun 89 15:13:26 GMT References: <4112@merlin.usc.edu> Sender: news@megatek.UUCP Distribution: na Lines: 43 From article <4112@merlin.usc.edu>, by danking@aludra.usc.edu (Dan King): > (forgive me if this has been talked about before, but I can't seem to > solve the problem) > > I'm writing a Turbo C program that needs to shell out to DOS in order > to execute another file. This file will be either .EXE or .BAT, but I > don't have any easy way of telling which (well, I have written a > directory scanning routine that returns it, but that's beside the > point). Everything works fine if I use .EXE files. > > My problem is that I can't seem to be able to use either the EXEC or > SPAWN calls to execute a .BAT file. A perusal of the TC documentation > reveals that the EXEC and SPAWN calls will automatically search for > .EXE files, but don't seem to be able to deal with .BAT files at all. > > Is there any way to accomplish what I'm trying to accomplish? > This information is not necessarily accurate but should point you in the right direction to get the correct information. What you should do is to EXEC or SPAWN command.com with, I believe, the /c switch followed by the name of the EXE or BAT file. Command.com will then be able to search for the EXE or BAT and either program load or batch process as appropriate. The problem you are running into is that EXEC and SPAWN only know how to load and execute A PROGRAM. A batch file is not a program, but merely a text file of input for a program, command.com. I believe, also, that if command.com notes that what you have asked it to "run" is an EXE, then it will allow the non-resident portion of itself to be swapped out if necessary to provide memory for your program to run in. If it notices that you have requested "execution" of a batch file, it will remain completely resident and execute the batch file. Dion Hollenbeck (619) 455-5590 x2814 Megatek Corporation, 9645 Scranton Road, San Diego, CA 92121 seismo!s3sun!megatek!hollen ames!scubed/