1

I was testing out a batch file and I put in pauses to double check that the script was functioning properly.

My question is, if the script encounters a pause, and I alter the script, either add a line or take one out, save it, and hit a key to continue, will my changes also load or do I have to run the batch file again for my changes to take effect?

0

2 Answers 2

2

What happens if I alter a batch file when it is paused

Changes made to the batch file after the pause statement are reflected in the results.

Changes made to the batch file before the pause statement are ignored, provided they don't change the number of characters. See answer by sgmoore for the reason why.

2
  • So, technically I don't have to run my batch file again? Just hit any key to continue.
    – user407055
    Apr 14, 2015 at 18:07
  • Yes, subject to the restrictions above.
    – DavidPostill
    Apr 14, 2015 at 19:46
2

Changes made to the batch file after the pause statement are fine and will take effect when you hit any continue to continue.

But I would strongly recommended you do not change anything before the pause statement.

Windows remembers what position it is at, so changes made to the batch file before the pause statement can affect your batch file in weird ways and can cause serious problems.

For example, if you have a trivial batch file that does something like

@Rem 
@Echo "Hello"
pause
@Echo  Dir c:\windows

When the pause is executed, windows reckons it is at the 27th byte of the file. If you remove the first line, then because you have removed five characters, everything is shifted, but when you press any key, windows will continue from 27th character.

So instead of issuing the command

 @Echo  Dir c:\windows 

it issues a

 Dir c:\windows

Now imagine what would happen if your original batch said

@Echo Del c:\windows
1
  • HA! Good catch. Never thought of that.
    – user407055
    Apr 15, 2015 at 11:34

You must log in to answer this question.