CFOG's PIP, February 1987, Volume 5 No. 4, Whole No. 52, page 5

MS-DOS Batch File Processing

by Ernest Perez

[This article is a file I downloaded from Henry Kisor's Word Processing BBS. It was posted there on 12- 31-1986 by Ernest Perez. -- bhc]

I have found out a deep, dark, batch file "programming" secret. I'd always thought you could not call a batch file as a SUBROUTINE from another batch file. For instance, I couldn't create a BAT1.BAT, stick a call to BAT2.BAT somewhere in the middle of BAT1, and have processing return to BAT1 to finish up, after executing BAT2. It would go to BAT2, and that was the end.

I caught a mention in the DOS manual that implied you can do it, but couldn't figure out how to. And now, here's the secret....

In the "calling" batch file, you have to restart COMMAND. COM... To do this, enter this batch command line:

command /c <batchfilename

The called file will execute, and return processing to the first batch file!

My first trial was the following (it worked).

rem this is the calling .BAT file,
rem about to make the call...
command /c try2
rem And this is the rest of the first .BAT
rem file, about to display a single
rem column directory.
rem THE END...
rem this is the called file,
rem displaying a wide directory...
dir /w
pause The called batch file is now finished...

Pleasant 'puter playing...