Exit / B 0 does not work

I have the following problem:

I created a script package that calls itself there (to be able to write a log in parallel). In the script, I start another process (e.g. start startServer.bat ) that starts the Java process and keeps opening all the time.

In my original script, I wait 30 seconds, check if the process is running and execute:

 exit /B 0 

Unfortunately, this does not work, the window shows that exit / B 0 is being calculated, but the window still remains open. When I close the window with another process (this means that the "child" processes are running in my .bat), my script continues to run.

So:

scriptA.bat

 -> in there I call: start startServer.bat -> wait 30 seconds -> check is server is started -> exit /B 0 Process hangs up! 

Which is very strange if I wrap another script, for example:

scriptB.bat

 -> call scriptA.bat -----> in there I call: start startServer.bat -----> wait 30 seconds -----> check if server is started -----> exit /B 0 -> scriptA.bat continues without any hangup! 

I also tried the same with output 0 (without / B) too, same result! In the first case, it freezes, in the second case, my window closes as expected ...

Have any of you ever experienced such a problem and knew what was wrong here? The process freezes!

+4
source share
2 answers

There is a good explanation of all the options for exiting the script package here: http://www.robvanderwoude.com/exit.php

In particular, from this page:

DOS online help (HELP EXIT) makes it impossible to understand that the / B option exits the current instance of the script, which does not necessarily coincide with the output of the current script. That is, if the script is in a CALLed code fragment, EXIT / B exits CALL, not the script.

Therefore, you definitely do not want exit /b 0 in this case. If just exit 0 doesn't work, try GOTO:EOF .

+6
source

I think your problem is the start command. The following excerpt from start /? help may indicate a problem:

Team / program

If it is an internal cmd command or a batch file, then the shell starts with the / K switch in cmd.exe. This means that the window will remain after the command is executed.

If this is not an internal cmd command or a batch file, then this is a program and will work as a windowed application or console application.

As a solution, you can try changing the launch command as follows:

 start "" cmd /c "startServer.bat" 
0
source

Source: https://habr.com/ru/post/1310485/


All Articles