windowsbatch-filescriptingterminatecontrol-c

How to terminate only the inner batch job


Let's say there is some .bat file that is required to run inside .cmd batch script. This inner .bat file has a series of user interactions on a local host, and are only able to be ended using ctrl+c.

The question is: Is there some way to make the outer batch script resume after the inner script is terminated? Or is the ctrl+c the end all be all?

I've tried giving the inner script a different way out only to be told I'm not allowed to change that file. I've also done a fair amount of research and haven't found a solution. Forgive me if I've overlooked something! I'd like to avoid having two windows or extraneous termination messages pop up.


Solution

  • The only way I can think of to handle this is to use the following line in outer.cmd to call inner.bat -- with the disadvantage of receiving a new command prompt window for the execution of inner.bat:

    start "" /WAIT cmd /C "inner.bat"
    

    (Exchanging start and cmd does not work as the new window might unintentionally remain open.)

    Note that for inner.bat, all the console input and output are handled via the new window, hence any redirections for outer.cmd (e. g., outer.cmd > "return.txt") will not include data from inner.bat.