exit / B 0不工作 [英] exit /B 0 does not work
问题描述
我有以下问题:
我创建了一个批处理脚本,在那里调用自己(为了能够并行写一个日志)。在脚本中我启动另一个进程(如 start startServer.bat
),它启动一个java进程并始终打开。
I have created a batch script which calls itself in there (for being able to write a log in parallel). In the script I start another process (like start startServer.bat
) which starts up a java process and keeps opened up all the time.
在我的原始脚本中,我等待30秒,检查进程是否正在运行,并执行:
In my original script I wait 30 seconds, check if the process is running and do an:
exit /B 0
很遗憾,这不起作用,窗口显示退出/ B 0正在计算,但窗口仍然保持打开。当我关闭窗口与其他进程(意味着子进程启动在我的.bat)我的脚本继续运行。
Unfortunately that does not work, the window shows that the exit /B 0 is being evaluated, but the window still keeps open. When I close the window with the other process (meaning the "child" processes started up in my .bat) my script continues its run.
所以:
scriptA.bat
-> in there I call: start startServer.bat
-> wait 30 seconds
-> check is server is started
-> exit /B 0
Process hangs up!
很奇怪,如果我包装另一个脚本,如:
What's very odd, if I wrap another script around, like:
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!
我也尝试了同样退出0(没有/ B)也,同样的结果!在第一种情况下,它挂起,在第二种情况下,我的窗口按预期关闭...
I also tried the same with exit 0 (without /B) also, same result! In the first case it hangs up, in the second case my window closes as expected...
有任何人曾经有过这样的问题, ?
进程挂起!
Has anyone of you ever had such a problem before and knows what's wrong here? Process hangs up!
推荐答案
这里有一个很好的退出批处理脚本的选项:
http://www.robvanderwoude.com/exit.php
There's a good explanation of all the options for exiting a batch script here: http://www.robvanderwoude.com/exit.php
具体来说,从那个页面:
DOS在线帮助(HELP EXIT)并没有清楚表明/ B参数退出脚本的当前实例,这不一定是与退出当前脚本相同。
I.e如果脚本在CALLed代码段中,EXIT / B退出CALL,而不是脚本。
Specifically, from that page: The DOS online help (HELP EXIT) doesn't make it clear that the /B parameter exits the current instance of script which is not necessarily the same as exiting the current script. I.e. if the script is in a CALLed piece of code, the EXIT /B exits the CALL, not the script.
所以你肯定不想要 exit / b 0
在这种情况下。如果只是退出0
不工作,请尝试 GOTO:EOF
。
So you definitely don't want exit /b 0
in this case. If just exit 0
doesn't work, try GOTO:EOF
.
这篇关于exit / B 0不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!