简体   繁体   English

关闭特定的命令提示符

[英]close a particular command prompt

I have opened a commnad prompt using java program and another command prompt manually.我已经使用 java 程序和另一个命令提示符手动打开了一个命令提示符。 Now my requirement is that i need to close the command prompt that i have opened by java program using the program.现在我的要求是我需要使用该程序关闭 java 程序打开的命令提示符。

I tried to close this by giving rt.exec("taskkill /IM cmd.exe");我试图通过给出 rt.exec("taskkill /IM cmd.exe"); 来关闭它。

But the problem is that the command prompt that i have opened manually is aslo closed which i dont want.但问题是我手动打开的命令提示符也关闭了,这是我不想要的。

Help needed.需要帮助。 Thanks in advance提前致谢

It's simple -这很简单 -

Step 1 - Create a batch file (say closeCMD.bat ) Step 1 - 创建一个批处理文件(比如closeCMD.bat

Step 2 - write exit in closeCMD.bat Step 2 - 在closeCMD.bat中写入exit

Step 3 - call above batch file in your java code as below - Step 3 - 在您的 java 代码中调用上述批处理文件,如下所示 -

Runtime.getRuntime().exec("cmd /c start closeCMD.bat"); Runtime.getRuntime().exec("cmd /c start closeCMD.bat");

That's it !!而已 !! Cheers!!干杯!!

if you're using Runtime.getRuntime().exec(), it returns a Process object.如果您使用的是 Runtime.getRuntime().exec(),它会返回一个进程 object。 You should hold on to that and call Process.destroy() when you're done.你应该坚持下去,完成后调用 Process.destroy() 。

you can try to program "exit" into the command prompt after you are done with your tasks in command prompt在命令提示符下完成任务后,您可以尝试将“退出”编程到命令提示符中

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

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