Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid exit of Windows cmd terminal if called command executes `exit`?

In a Windows cmd terminal, by cmd, I call command scripts (.cmd), but some of these does an exit [code] without the /B, whereby my Windows terminal is terminated.

How to avoid exit of Windows cmd terminal if called command executes exit without the /B?

like image 248
EquipDev Avatar asked Oct 25 '25 13:10

EquipDev


1 Answers

You could invoke scriptname.cmd with cmd /c. That way exit will exit your cmd /c invocation, rather than the ancestral console process.

Test1.bat:

@echo off & setlocal

echo Exiting.
exit 0

Test2.bat:

@echo off & setlocal

echo Invoking Test1.bat
cmd /c Test1.bat

echo Still running!

Output of Test2.bat:

Invoking Test1.bat
Exiting.
Still running!

... and the console window remains open.

like image 96
rojo Avatar answered Oct 28 '25 07:10

rojo