danking@aludra.usc.edu (Dan King) (06/17/89)
(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? Thanks for any help, dank
mms00786@uxa.cso.uiuc.edu (06/19/89)
This is a total shot in the dark, but here goes: If you know that it is a bat file you need to execute, you might want to execute command.com with the parameter "/c filename.bat". In other words, use the exec function to execute a copy of command.com and give it the online argument "/c filename.bat". I am assuming that if you can execute .exe files, then you won't have problems executing command.com either. So the arg0 pointer in the argument list for exec should point to a string containing "/c filename.bat". Never tried this, and am not about to; but I hope this helps. Milan. mms00786@uxa.cso.uiuc.edu .
hollen@zeta.megatek.uucp (Dion Hollenbeck) (06/19/89)
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/
wew@naucse.UUCP (Bill Wilson) (06/20/89)
From article <4112@merlin.usc.edu>, by danking@aludra.usc.edu (Dan King): > 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. > You may try using the system function instead of the others. The system command loads another copy of command.com and executes the commands that you give as the parameter. Hope this helps! -- Bill Wilson (Bitnet: ucc2wew@nauvm) Northern AZ Univ Flagstaff, AZ 86011 {Let sleeping dragons lie......}
ho@fergvax.unl.edu (Michael Ho) (06/20/89)
From article <584@megatek.UUCP>, by hollen@zeta.megatek.uucp (Dion Hollenbeck): > 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. I think you can also use the system() call to do it -- the system() basically passes a command line to the shell. Whether it does it with spawn() or with the evil undocumented interrupt, I don't know. --- Michael Ho, University of Nebraska <ho@fergvax.unl.edu> For the next 60 lines, we will be conducting a test of the emergency
ralf@b.gp.cs.cmu.edu (Ralf Brown) (06/20/89)
In article <584@megatek.UUCP> hollen@zeta.megatek.uucp (Dion Hollenbeck) writes: }From article <4112@merlin.usc.edu>, by danking@aludra.usc.edu (Dan King): }> [how do I SPAWN or EXEC a .BAT file] }> }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. correct. }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. This is not how it works. The nonresident portion is located at the upper end of memory, and is not protected from overwriting by any executables. Each time that COMMAND.COM regains control, it checks whether its transient portion has been overwritten, and reloads it if necessary. COMMAND regains control after an executable has been run (either .COM or .EXE can overlay the transient portion), or after a line of a batch file has been executed. A batch file can cause the overlaying of the transient portion if it invokes a program that does so. -- {harvard,uunet,ucbvax}!b.gp.cs.cmu.edu!ralf -=-=- AT&T: (412)268-3053 (school) ARPA: RALF@B.GP.CS.CMU.EDU |"Tolerance means excusing the mistakes others make. FIDO: Ralf Brown at 129/31 | Tact means not noticing them." --Arthur Schnitzler BITnet: RALF%B.GP.CS.CMU.EDU@CMUCCVMA -=-=- DISCLAIMER? I claimed something? --