0

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.

xandermonkey
  • 4,054
  • 2
  • 31
  • 53
  • So you are using `call inner.bat` to run the inner script? Perhaps `cmd /C inner.bat` or `start "" /WAIT inner.bat` could help... – aschipfl Jul 06 '16 at 19:34
  • @aschipfl thanks that's quite helpful, the cmd /C works but now I get two Termination requests. Would like to just terminate the inner one and have the outer one continue smoothly – xandermonkey Jul 06 '16 at 19:37
  • @aschipfl same issue with the start in new window. Thanks though, definitely closer. – xandermonkey Jul 06 '16 at 19:41
  • @aschipfl other good option would be to have two termination messages where the first one is the standard message but the second one is suppressed/custom message. Any advice on this? – xandermonkey Jul 06 '16 at 20:03
  • What about combining like `start "" /WAIT cmd /C inner.bat` or `cmd /C start "" /WAIT inner.bat`? concerning a custom message I am afraid I cannot help you... – aschipfl Jul 06 '16 at 20:17
  • 2
    Possible duplicate of [Running batch file, call another batch, ctrl+c out of that, then return to the first?](http://stackoverflow.com/questions/18181887/running-batch-file-call-another-batch-ctrlc-out-of-that-then-return-to-the-f) – aschipfl Jul 06 '16 at 20:17
  • You might also be interested in this post: [batch script if user press Ctrl+C do a command before exitting](http://stackoverflow.com/a/27131024) – aschipfl Jul 06 '16 at 20:18
  • @aschipfl Thanks, between those two I'll be all set. Feel free to post those two as an answer if you want! Sorry I missed them in my previous searches. Second link is the most helpful, not sure I like the double window idea. Thanks again. – xandermonkey Jul 06 '16 at 20:21
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/116617/discussion-between-alex-rosenfeld-and-aschipfl). – xandermonkey Jul 06 '16 at 21:06

1 Answers1

1

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.

aschipfl
  • 33,626
  • 12
  • 54
  • 99