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

bawsi
  • 885
  • 2
  • 14
  • 23
  • 1
    Can you provide a [MCVE] of the behavior? Both batch file and python? – Jeff Zeitlin Mar 12 '18 at 17:03
  • Possible duplicate of [How to automatically close cmd window after batch file execution?](https://stackoverflow.com/questions/14697739/how-to-automatically-close-cmd-window-after-batch-file-execution) – user3483203 Mar 12 '18 at 17:11
  • Added an example of batch script I use, it just runs a python file and passes it two variables – bawsi Mar 12 '18 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? – Meet Dec 09 '21 at 11:27

1 Answers1

2

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.

u8it
  • 3,482
  • 1
  • 17
  • 30
D. Pardal
  • 5,634
  • 1
  • 15
  • 34