0

Consider two bat files.

outer.bat

echo Before
inner.bat
echo After

inner.bat

echo Inner
goto :eof

When I execute outer.bat "After" is not echoed. So "goto :eof" in the inner script terminates the outer script.

Can I rewrite outer.bat to continue execution after calling inner.bat without modifying inner.bat?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
alexey
  • 8,360
  • 14
  • 70
  • 102

1 Answers1

4

Batch files have a single execution context. When you nest batchfile calls like that, the nested file completely replaces the outer/parent batch file's context. There's no record saying that there was a parent batch file, so you simply return to the prompt when the inner file completes.

To be able to return to the outer batch file, you have to do

 echo Before
 call inner.bat
 echo After
Marc B
  • 356,200
  • 43
  • 426
  • 500