Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does my .bat file abruptly end after calling another .bat file?

Tags:

batch-file

cmd

Relatively simple thing here without a readily discoverable answer...I've tried variations of start, /K flags, etc etc, but whenever my batch file hits the servicecontroller line and runs that command it completes the command but doesn't do anything after. Please advise.

cd c:\blackboard\tools\admin
servicecontroller.bat services.stop
echo ! ! ! Blackboard services have successfully stopped. It is now safe to shut down the computer or database server. ! ! !
timeout /15
like image 370
Christopher Bruce Avatar asked Mar 18 '23 08:03

Christopher Bruce


1 Answers

batch files have no memory where any particular line came from. If you execute another batch file from within a batch file, the original file is essentially "gone".

foo.bat:

echo in foo
bar.bat
echo called bat  <--never called

bar.bat:

echo in bar

baz.bat:

echo in baz
call bar.bat
echo back in baz   <--will be called

Note the call in baz.bat. It's vaguely/kinda/sorta the difference between goto and gosub. goto unconditionally transfers control to the new location, while "gosub" allows for a "return" to the original calling context.

like image 172
Marc B Avatar answered Mar 23 '23 00:03

Marc B