How to interrupt a running Batch file, execute a command in its environment, then continue?

I'm aware that I can interrupt a running batch file witch Crtl-C, and then continue the execution.

However, is it possible to execute a command in the batch file's cmd environment while the batch is paused?

For example, I might want to pause a running batch, change some variables it has SET previously, then continue the execution.


Solution 1:

Add lines in the batch with modifications (i.e. set new value to the variable) after pause and continue the batch

Solution 2:

This code will allow to execute arbitrary commands from within batch context: Put it a batch file and play with it.

@echo off

:loop 
  set cmd=
  set /p "cmd=Please give command, empty line to finish "
  if defined cmd (
    call %cmd%
    goto loop
  )

To finish executing commands just hit Enter

To use it in your batch, just insert a line with call to above:

do stuff 
do more stuff

call interrupt_me.bat

do even more stuff

If you wonder why there is a call %cmd% instead of straight %cmd% - it allows to expand variables passed so commands like echo %comspec% work properly.