[comp.os.msdos.programmer] Batch Files

migdol@emx.utexas.edu (Michael A. Migdol) (05/23/91)

I'll probably get told to RTFM on this one, but here goes, anyways: Does
MS-DOS read a batch file as it's running from disk, or does it load it all
into memory at the beginning? In other words, if I have an autoexec.bat file
that loads in a new autoexec.bat file, It will try to start running the 2nd
file, right?

Thanks in advance!


*****************************************************************************
*  Michael A. Migdol                  |    Disclaimer:                      *
*  migdol@emx.utexas.edu              |       "I may be wrong"              *
*  University of Texas, Austin        |           (Thanks Robert Fulghum!)  *
*****************************************************************************
*               "There's no such thing as a simple miracle"                 *
*****************************************************************************

dahosek@biivax.dp.beckman.com (05/24/91)

In article <49377@ut-emx.uucp>, migdol@emx.utexas.edu (Michael A. Migdol) writes:
> I'll probably get told to RTFM on this one, but here goes, anyways: Does
> MS-DOS read a batch file as it's running from disk, or does it load it all
> into memory at the beginning? In other words, if I have an autoexec.bat file
> that loads in a new autoexec.bat file, It will try to start running the 2nd
> file, right?

It reads the file as it goes. If a batch file modifies itself as
it executes, I have no idea what happens.

-dh

-- 
Don Hosek // Quixote Digital Typography   714-625-0147
     dhosek@ymir.claremont.edu
On contract to Beckman Instruments        714-961-4562
     dahosek@beckman.com

erick@sunee.waterloo.edu (Erick Engelke) (05/24/91)

In article <49377@ut-emx.uucp> migdol@emx.utexas.edu (Michael A. Migdol) writes:
>I'll probably get told to RTFM on this one, but here goes, anyways: Does
>MS-DOS read a batch file as it's running from disk, or does it load it all
>into memory at the beginning? In other words, if I have an autoexec.bat file
>that loads in a new autoexec.bat file, It will try to start running the 2nd
>file, right?
>
>Thanks in advance!
>

It will once again open the file, seek to the position assumed to be the
next line and try to read the command.  If you wish to change the batch
file, make certain you change it AFTER your current position or else you
start getting problems.

-- 
----------------------------------------------------------------------------
Erick Engelke                                       Watstar Computer Network
Watstar Network Guy                                   University of Waterloo
Erick@Development.Watstar.UWaterloo.ca              (519) 885-1211 Ext. 2965

IO92203@MAINE.MAINE.EDU (Scott Maxell) (05/27/91)

In article <49377@ut-emx.uucp>, migdol@emx.utexas.edu (Michael A. Migdol) says:
>
>I'll probably get told to RTFM on this one, but here goes, anyways: Does
>MS-DOS read a batch file as it's running from disk, or does it load it all
>into memory at the beginning? In other words, if I have an autoexec.bat file
>that loads in a new autoexec.bat file, It will try to start running the 2nd
>file, right?

A batch file is opened, one line is read from it, then closed, then the line
is executed. If a batch file calls another batch, that line will be read, the
line marker for the first file saved, then the next batch runs. After that
batch file finishes executing, the first is opened again and the next line
is read.

//////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
+---------+ Scott Maxell  -- Bitnet   ->> IO92203 @ maine
|         |               -- Internet ->> IO92203 @ maine.maine.edu
|    O    |
|    |    | "What I need is a computer that will do what I want it to
+---------+ do, not what I tell it to do..."

jkelly@violet.berkeley.edu (John Kelly;;25241;;LN41) (06/19/91)

In article <91146.162307IO92203@MAINE.MAINE.EDU>
IO92203@MAINE.MAINE.EDU (Scott Maxell) writes:

>A batch file is opened, one line is read from it, then closed, then the line
>is executed. If a batch file calls another batch, that line will be read, the
>line marker for the first file saved, then the next batch runs. After that
>batch file finishes executing, the first is opened again and the next line
>is read.

What version of MS/PC-DOS are we talking about here?  In the versions I
know only too well (up to 3.21), this does NOT happen (would that it
did!).  When a batch file calls another batch file, control transfers to
the called file and never returns--unless you make the call using the
syntax "command /cSECOND.BAT".  This loads another copy of command.com
with instructions to execute SECOND.BAT; when that copy of command.com
finishes, it exits to the original batch file and goes on.

For example, given:
	FIRST.BAT			SECOND.BAT	
	echo This is line 1 of FIRST	echo Line 1 of SECOND
	second
	echo Line 3 of FIRST

you will never see the message "Line 3 of FIRST".  You have to rewrite
FIRST.BAT:
	echo This is line 1 of FIRST
	command /cSECOND
	echo Line 3 of FIRST

Right, I just said it couldn't be done and then told you how to do it.
It's late and I should be in bed.  Anyway, my point is that you can't
do it by just calling the second batch file--you have to jump through a
hoop.  Remember, MS-DOS was originally designed to run on 64K IBM PC's;
it's no wonder we have to twist it up like a pretzel to make it do the
things a real operating system does.

Scott is right about the line-by-line reading and executing.  That's
why it's so easy to get the message "Insert disk with batch file and
press any key to continue."