8

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.

7
  • 1
    add lines with modifications (i.e. set new value to the variable) after pause and continue the batch
    – jet
    Sep 2, 2012 at 19:34
  • such a simple solution! :) unfortunately, can't select comment as answer
    – vedran
    Sep 2, 2012 at 22:01
  • @jet: How would one continue execution of the batch file where it left off (i.e. right after the pause command)?
    – martineau
    Sep 3, 2012 at 0:47
  • @vedran: I added it as an answer
    – jet
    Sep 3, 2012 at 1:04
  • @martineau: before pause, put command.com for example... and then you know... exit and you are back to the batch, maybe there is a better way
    – jet
    Sep 3, 2012 at 1:04

2 Answers 2

1

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

3

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .