1

The command interpreter is running a .bat or .cmd.

What will be the behaviour of cmd.exe if I edit and save this .bat while it is running? Is it documented anywhere?

double-beep
  • 5,031
  • 17
  • 33
  • 41
Benoit
  • 76,634
  • 23
  • 210
  • 236
  • @KristerAndersson, thanks, had not seen this one. Voting to close. – Benoit Mar 09 '12 at 13:06
  • 1
    why not try it out and see for yourself? :) – Aman Mar 09 '12 at 13:07
  • @Amn, because observing a certain behaviour does not mean that the behaviour is documented, guaranteed, and that it is not simply undefined thus non-reproductible. – Benoit Mar 09 '12 at 13:09
  • In Ansi-C this is correct, but in batch there isn't nearly nothing correct documented. So you can only test on different systems and hope that a certain behaviour wont be changed next time – jeb Mar 09 '12 at 14:39

1 Answers1

0

It actually depends on where you make the changes. The question linked above has what I feel are the right answers (actually I think rein's answer was better than Binary Worrier's), but I feel the need to leave this here.

I highly recommend against changing the batch file while it's running. Stop the job, make your changes, and retry. This is of the essence for proper testing in my opinion.

If you are intending for the batch file to update itself, I would highly recommend against it. Create another batch file from your original and call that batch. This is a far safer method in my opinion.

UnhandledExcepSean
  • 12,504
  • 2
  • 35
  • 51
  • I append also an [answer](http://stackoverflow.com/a/9635783/463115) just now, as even the answer of rein isn't complete – jeb Mar 09 '12 at 14:37
  • Although it may not be ideal, if you _really_ want to modify it while it's running https://stackoverflow.com/a/56949764 might help – sparrowt Feb 23 '23 at 15:42