2

I have batch file that runs python script. But, once python script finishes, cmd stays open.. How can I close it?

Thank you!

Edit: .bat script looks something like this:

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?

Edit2: Nevermind, figured it out. You can just add exit at end of the batch file, and it will run once the python script ends

4
  • 1
    Can you provide a minimal reproducible example of the behavior? Both batch file and python? Commented Mar 12, 2018 at 17:03
  • Possible duplicate of How to automatically close cmd window after batch file execution? Commented Mar 12, 2018 at 17:11
  • Added an example of batch script I use, it just runs a python file and passes it two variables Commented Mar 12, 2018 at 18:09
  • Is there a way to close the bat cmd file even when the python program is running? I have a python program that will run in background. I want to execute it but without showing this cmd screen. How to do that? Commented Dec 9, 2021 at 11:27

1 Answer 1

4

Just create a line with the exit command at the end of the batch file. That will close the cmd window when it reaches the end.

Sign up to request clarification or add additional context in comments.

1 Comment

you can also use ctrl + c

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.