Computer Hope

Microsoft => Microsoft DOS => Topic started by: powlaz on February 28, 2020, 10:22:50 AM

Title: CMD window doesn't close after batch script executes
Post by: powlaz on February 28, 2020, 10:22:50 AM
I call several batch scripts from a master batch script (that I use for maintenance) without any issue but there is this one script that will not exit when it's done running and I don't know why.  When I simply run the script it does exactly what I expect it to do - it executes and then exits when it is done running (CMD window closes).  When I call the script from my master script it executes (in a separate window, which is what I want) but its CMD window doesn't close. 

I call all my batch scripts like this:  Start /wait Call "<script>"
I can't for the life of me figure out why the CMD window won't close for this one.

Here's the Chrome script:
Code: [Select]
cls
@echo off
TITLE Google Chrome Updater

Set /P=Installing Google Chrome and dependencies.....<NUL
taskkill /im chrome.exe /f >NUL 2>&1
::-----Install Chrome-----::
Start /wait MSIEXEC.EXE /I "\\<pathtoInstaller>\GoogleChromeStandaloneEnterprise64.msi" /qb-! >NUL
::-----Install Legacy Browser Support-----::
Start /wait MSIEXEC.EXE /I "\\<pathtoInstaller>\LegacyBrowserSupport_5.9.0.0_en_x64.msi" /qb-! >NUL
Echo Done!
timeout /t 4 >NUL

Set /P=Configuring Google Chrome..... <NUL
del "C:\Users\Public\Desktop\*.lnk" /Q >NUL 2>&1
sc stop "gupdate" >NUL
sc config "gupdate" start= disabled >NUL
sc stop "gupdatem" >NUL
sc config "gupdatem" start= disabled >NUL
schtasks /delete /tn GoogleUpdateTaskMachineCore /f >NUL 2>&1
schtasks /delete /tn GoogleUpdateTaskMachineUA /f >NUL 2>&1

Echo Done!
Exit /B %ErrorLevel%

pause

The pause at the end is for testing.  I can confirm that the script actually exits at Exit /B because the "pause" is not executed.  With or without the "pause" the CMD window doesn't close.  Help!
Title: Re: CMD window doesn't close after batch script executes
Post by: Geek-9pm on February 28, 2020, 11:08:47 AM
You can find help on most things on your PC.
Try this at the command level:

help exit

It will explain the /B thing alters the behavior of the exit.


Title: Re: CMD window doesn't close after batch script executes
Post by: powlaz on March 03, 2020, 08:24:40 AM
Thanks for the reply but I was hoping for better help than a reference to the help file.  The help file doesn't explain why when other scripts that I call exit the CMD window closes.  I know I want to end the scripts with Exit /B or Goto :EOF - I don't know what could explain why the CMD window doesn't close when the script I posted is done executing.  Anyone else have an idea?

Thanks,

MJ
Title: Re: CMD window doesn't close after batch script executes
Post by: Geek-9pm on March 03, 2020, 10:27:21 AM
OK. I will try again. There are two kinds of EXIT.
There is just EXIT which does just that and noting else.
The other does something else.

In other words, you can only use plain EXIT.
Title: Re: CMD window doesn't close after batch script executes
Post by: BC_Programmer on March 03, 2020, 07:16:24 PM
The /B Switch literally means to only exit the batch file and leave CMD open.
Title: Re: CMD window doesn't close after batch script executes
Post by: powlaz on March 06, 2020, 05:26:38 AM
My apologies fellas.  I could tell you a long story about all that I tried and experienced in testing but it would still end in me changing "Exit /B" to "Exit" and solving the problem.  I don't understand why "Exit /B" works the way I want it to in my other scripts but am thankful that it does.  Thank you.

MJ