简体   繁体   English

批处理文件中的所有过程完成后,关闭Windows命令提示符

[英]close windows command prompt after all process completed in the batch file

I have two batch files I need to run. 我有两个需要运行的批处理文件。 Two different java files are called in those two bat file. 在这两个bat文件中调用了两个不同的java文件。

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 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

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. J1会自行打开命令提示符(cmd提示符窗口#1)并触发batch2.bat(cmd提示符窗口#2),并且在batch2完成后,J1会做其他几件事然后退出。 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. 因此,我绝对需要关闭cmd提示符窗口#2并返回到cmd提示符窗口#1,以便J1可以完成它必须执行的操作。

Right now, after batch2.bat is done, the window stays and obviously it does not return control to cmd prompt window #1. 现在,batch2.bat完成后,该窗口将保留,并且显然不会将控制权返回给cmd提示窗口#1。

Here are the two batch files 这是两个批处理文件

batch1.bat 批处理1.bat

call J1 batch2.bat
exit

batch2.bat 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

I have tried the following but none of them will close cmd prompt window#2 我尝试了以下操作,但没有一个可以关闭cmd提示窗口#2

  • start J2 p2 p2 p2_args (this will open another window and does not close cmd prompt window#2 启动J2 p2 p2 p2_args(这将打开另一个窗口,并且不会关闭cmd提示窗口#2
  • start "" J2 p2 p2_args (this will open another window and does not close cmd prompt window#2) 启动“” J2 p2 p2_args(这将打开另一个窗口,并且不会关闭cmd提示窗口#2)
  • start /b cmd /c J2 p2 p2_args (this will not open a new window but does not close cmd prompt window#2) start / b cmd / c J2 p2 p2_args(这不会打开新窗口,但不会关闭cmd提示窗口#2)
  • use exit /b in batch2.bat (does not close cmd prompt window#2) 在batch2.bat中使用退出/ b(不关闭cmd提示窗口#2)

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. 我还尝试将这两个p2和p3放在单独的bat文件中,并从batch2.bat调用该bat文件,但是该命令提示符窗口仍然无法关闭。

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! 谢谢!

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. 经过观察,我注意到在cmd进行“退出”之后,它将不会返回到提示,并且我必须按Enter才能使事情继续进行。 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%

It's from this post, Explain how dos-batch newline variable hack works 这是来自这篇文章, 解释dos-batch换行符变量hack的工作方式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM