简体   繁体   English

批处理运行python脚本..最后如何关闭cmd窗口?

[英]Batch runs python script.. how to close cmd window at end?

I have batch file that runs python script.我有运行 python 脚本的批处理文件。 But, once python script finishes, cmd stays open.. How can I close it?但是,一旦 python 脚本完成,cmd 就会保持打开状态。我该如何关闭它?

Thank you!谢谢!

Edit: .bat script looks something like this:编辑:.bat 脚本如下所示:

C:\Users\USER\AppData\Local\Programs\Python\Python36\python.exe C:\Users\USER\Documents\Code\python\some-dir\script.py %1 %2

And then python script runs, and once it ends, cmd window from batch file remains open.. Can I close it somehow from python script itself or something?然后python脚本运行,一旦结束,批处理文件中的cmd窗口保持打开状态..我可以从python脚本本身或其他东西以某种方式关闭它吗?

Edit2: Nevermind, figured it out. Edit2:没关系,想通了。 You can just add exit at end of the batch file, and it will run once the python script ends您可以在批处理文件的末尾添加exit ,它会在 python 脚本结束后运行

Just create a line with the exit command at the end of the batch file.只需在批处理文件的末尾用exit命令创建一行。 That will close the cmd window when it reaches the end.这将在结束时关闭 cmd 窗口。

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

相关问题 Python 脚本中的 BS4 错误.. 在 PyCharm 中运行良好,但在操作系统中却没有 - BS4 error in Python script.. runs fine in PyCharm but not in OS 如何使用 python 2.7 关闭 cmd 窗口 - How to close a cmd window using python 2.7 启动一个简单的批处理文件以运行python脚本,然后终止cmd窗口 - start a simple batch file to run a python script then terminate the cmd window 关闭 Python Selenium 的命令行 window 使用 ZC89686A387D2BABC55BBatch3 运行后 - Close Python Selenium 's command line window after it runs using Window Batch 批处理脚本完成后如何关闭命令窗口 - How to close command window after batch script completion Python Scripting:如何使用python脚本在gdb提示符下执行unix命令..? - Python Scripting : how to execute unix commands inside gdb prompt using python script..? Python在退出时关闭自己的CMD shell窗口 - Python to close own CMD shell window on exit 执行python后cmd窗口没有关闭 - cmd window does not close after executing python Python脚本在启动时运行,然后在最后重新启动 - 如何重新获得控制权? - Python script runs on boot then reboots at end - How to regain control? 尝试从批处理文件运行 python 脚本,而不会弹出 cmd window - Trying to run a python script from a batch file without the cmd window popping up
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM