rupp@cod.UUCP (04/22/87)
Some while back there was a discussion of how to write a batch file that would call other batch files and then return control to the original batchfile (Sorry, this *is* confusing.). Anyway, I did not save any of the postings on the subject. Now it seems a local user would like to do this. Can someone shoot me an explanation of how this trick is accomplished? I would appreciate it. Please mail responses to: rupp%nosc.mil Thanks, Bill
nather@ut-sally.UUCP (Ed Nather) (04/23/87)
In article <626@cod.UUCP>, rupp@cod.UUCP (William L. Rupp) writes: > Some while back there was a discussion of how to write a batch file that > would call other batch files and then return control to the original > batchfile > Can someone shoot me an explanation of how this trick is > accomplished? command /c subr.bat -- Ed Nather Astronomy Dept, U of Texas @ Austin {allegra,ihnp4}!{noao,ut-sally}!utastro!nather nather@astro.AS.UTEXAS.EDU
bill@hpcvlo.HP.COM (Bill Frolik) (04/24/87)
To call another batch file from within a batch file, just invoke another copy of COMMAND.COM with a /C switch: ... echo This batch file calls "whatever.bat" command /c whatever.bat arg1 arg2 arg3 ... echo We return to here ... Be aware that since you are invoking a new command interpreter, the called batch file will live in a new "environment" (i.e., any variables that you have SET will not exist to the called file, and any variables that it SETs will disappear when control returns to the caller). DOS 3.3 has a new CALL command that lets you do batch file calling without having to do "command /c". Bill Frolik hp-pcd!bill Hewlett-Packard Portable Computer Division Corvallis, Oregon
anderson@uwmacc.UUCP (Jess Anderson) (04/26/87)
In article <1610013@hpcvlo.HP.COM|, bill@hpcvlo.HP.COM (Bill Frolik) writes: | echo This batch file calls "whatever.bat" | command /c whatever.bat arg1 arg2 arg3 ... | echo We return to here | Be aware that since you are invoking a new command interpreter, the called | batch file will live in a new "environment" (i.e., any variables that you | have SET will not exist to the called file, and any variables that it SETs | will disappear when control returns to the caller). I think the called batch file gets a *copy* of the environment as it exists at calling time, not a new environment. I agree that the environment of the child command.com is not passed back to the caller, so changes would be lost. This may be a function of the particular DOS -- I'm using MSDOS 3.1. -- ==ARPA:==============anderson@unix.macc.wisc.edu===Jess Anderson====== | UUCP: {harvard,seismo,rutgers, (avoid ihnp4!) 1210 W. Dayton | | akgua,allegra,usbvax}!uwvax!uwmacc!anderson Madison, WI 53706 | ==BITNET:======================anderson@wiscmacc===608/263-6988=======
nather@ut-sally.UUCP (Ed Nather) (04/26/87)
In article <1610013@hpcvlo.HP.COM>, bill@hpcvlo.HP.COM (Bill Frolik) writes: > > To call another batch file from within a batch file, just invoke another > copy of COMMAND.COM with a /C switch: > > Be aware that since you are invoking a new command interpreter, the called > batch file will live in a new "environment" (i.e., any variables that you > have SET will not exist to the called file, Not true. A copy of the current environment is supplied to the new command interpreter. > and any variables that it SETs > will disappear when control returns to the caller). This is true, unless your program can "set" a new string into the "living environment" rather than the copy. It is tedious but possible. -- Ed Nather Astronomy Dept, U of Texas @ Austin {allegra,ihnp4}!{noao,ut-sally}!utastro!nather nather@astro.AS.UTEXAS.EDU
brown@nicmad.UUCP (Mr. Video) (05/03/87)
In article <626@cod.UUCP> rupp@cod.UUCP (William L. Rupp) writes:
<Some while back there was a discussion of how to write a batch file that
<would call other batch files and then return control to the original
<batchfile (Sorry, this *is* confusing.). Anyway, I did not save any
<of the postings on the subject. Now it seems a local user would like to
<do this. Can someone shoot me an explanation of how this trick is
<accomplished? I would appreciate it.
PC-DOS 3.30 now supports a batch command called CALL. After call is
done, control is returned to the calling batch program.
I have not tested PC-DOS 3.21 to see if CALL is there already. Who knows,
maybe it is there and is one of the unsupported commands.
--
harvard-\ ihnp4--\
Mr. Video seismo!uwvax.......!nicmad!brown (How I hate 4 line .sigs!)
rutgers-/ decvax--/
terminus-/
catone@dsl.cis.upenn.edu (Tony Catone) (05/04/87)
In article <1651@nicmad.UUCP> brown@nicmad.UUCP (Mr. Video) writes: >In article <626@cod.UUCP> rupp@cod.UUCP (William L. Rupp) writes: ><Some while back there was a discussion of how to write a batch file that ><would call other batch files and then return control to the original ><batchfile ... > >PC-DOS 3.30 now supports a batch command called CALL. After call is >done, control is returned to the calling batch program. > >I have not tested PC-DOS 3.21 to see if CALL is there already. Who knows, >maybe it is there and is one of the unsupported commands. An earlier method to accomplish this task was to use a second copy of command.com, passing it the name of the subroutine batch file. I.e., your main batch file would contain a line like command /c batch2. Batch2 would then be executed, and upon completion control returns to your main batch file. The /c parameter is necessary to tell command.com to remove itself from memory after the program passed it on the command line is completed. I believe this method works on DOS version 2.x and above. This should look very familiar to any who have used DOS's exec function to push to a new shell from within their own application programs (just got this to work in Turbo Pascal, yea!). - Tony catone@dsl.cis.upenn.edu catone@wharton.upenn.edu