Interesting Tidbit: Batch Files in Windows 2003

I am not sure if this is just a new thing in Windows 2003, or it’s been this way for all time, but if you edit a batch file while it is executing, then you will change the behaviour of the script in real time. It seems that dos keeps a pointer to the last character it executed, and then when the current command it is executing returns, it resumes from (approximately) that character. Meaning if add a line or two this pointer will no longer be valid, causing unknown behaviour.

I was always under the impression that dos read in the whole batch file into memory, then ran it allowing you to edit the file in the meantime. The things you learn when you break a system, err, umm, are playing with dos batch files.

If you are bored, and have a lot of hard drive space, try this example (save as a.bat):

@echo off
type a.bat >> a.bat

(Make sure you have a trailing return character). For more fun, remove the pause and watch your free space shrink.

Post a comment or leave a trackback: Trackback URL.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: