批处理文件中的所有过程完成后,关闭Windows命令提示符 [英] close windows command prompt after all process completed in the batch file
问题描述
我需要运行两个批处理文件。在这两个bat文件中调用了两个不同的Java文件。
I have two batch files I need to run. Two different java files are called in those two bat file.
Java文件:J1.jar,J2.jar并包装在J1.bat中(xxx / java -jar J1.jar)和J2.bat
Bath文件:batch1.bat,batch2.bat
可执行程序:p1.exe,p2.exe,p3.exe,p4.exe
Java files: J1.jar, J2.jar and are wrapped in J1.bat (xxx/java -jar J1.jar) and J2.bat Bath files: batch1.bat, batch2.bat executable programs: p1.exe, p2.exe, p3.exe, p4.exe
J1会自行打开命令提示符(cmd提示符窗口#1)并触发batch2.bat(cmd提示符窗口#2),然后在batch2完成后,J1还会做其他几件事出口。因此,我绝对需要关闭cmd提示符窗口#2并返回到cmd提示符窗口#1,以便J1可以完成它必须执行的操作。
J1 will open a command prompt itself (cmd prompt window #1) and trigger batch2.bat (cmd prompt window #2) and after batch2 is done, J1 will do a couple of other things then exit. So I definitely need cmd prompt window #2 to close and return to cmd prompt window#1 so J1 can finish what it gotta do.
现在,在batch2.bat之后完成后,窗口将保留,并且显然不会将控制权返回给cmd提示窗口#1。
Right now, after batch2.bat is done, the window stays and obviously it does not return control to cmd prompt window #1.
这是两个批处理文件
batch1.bat
call J1 batch2.bat
exit
batch2.bat
call J2 p1 p1_args
start /b J2 p2 p2_args
start /b J2 p3 p3_args
call J2 p4 p4_args
exit
我尝试了以下操作,但没有一个会关闭cmd提示窗口#2
I have tried the following but none of them will close cmd prompt window#2
- 开始J2 p2 p2 p2_args(这将打开另一个窗口,并且不会关闭cmd提示窗口#2
- start J2 p2 p2_args(这将打开另一个窗口,并且不会关闭cmd提示窗口#2)
- start / b cmd / c J2 p2 p2_args(此w不会打开新窗口,但不会关闭cmd提示窗口#2)
- 在batch2.bat中使用exit / b(不会关闭cmd提示窗口#2)
- start J2 p2 p2 p2_args (this will open another window and does not close cmd prompt window#2
- start "" J2 p2 p2_args (this will open another window and does not close cmd prompt window#2)
- start /b cmd /c J2 p2 p2_args (this will not open a new window but does not close cmd prompt window#2)
- use exit /b in batch2.bat (does not close cmd prompt window#2)
我还尝试将这两个p2和p3放在单独的bat文件中,并从batch2.bat调用该bat文件,但是该命令提示符窗口仍然不会
I also tried to put those two p2 and p3 in a separate bat file and call that bat file from batch2.bat, but that command prompt window still wouldn't close.
有没有办法关闭第二个命令提示符窗口?我听说使用自动热键进行窗口脚本编写,这是一种解决方案和更好的窗口脚本编写方法吗?
Is there a way to close the second command prompt window?? I heard of using auto hot key to do window scripting, is that a solution and a better way to do window scripting?
我非常感谢您的帮助。谢谢!
I gratefully appreciate any help. Thank you!
推荐答案
观察后,我注意到cmd进行了退出操作后,它不会返回提示,我将必须按Enter才能开始。我决定在出口后放一个新行,它行得通。我用以下代码行替换了出口。
After observation, I notice that after cmd took "exit", it will not return to the prompt and I will have to press enter to get things going. I decided to put a new line after the exit and it worked. I swapped out the exit with the following lines of code.
@echo off
set NLM=^
set NL=^^^%NLM%%NLM%^%NLM%%NLM%
exit %NL%
来自此帖子,解释dos-批处理换行符变种黑客作品
这篇关于批处理文件中的所有过程完成后,关闭Windows命令提示符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!