1

I have run a console application,and i want it to directly close the entire cmd prompt window when the user enters 'exit' ive tried using exit(0) and sys.exit() but they just close the script only and not the actually cmd.prompt window.

1
  • Your answer has some formatting problems. Try to improve that to clarify the question. [TIPS]: Use ` brackets for paths and code fragments. To highlight apps' names or interface, use a bold (** brackets) or italic (* brackets) font.
    – maciejwww
    Commented Apr 18, 2021 at 17:18

1 Answer 1

2

It's not the cleanest approach but the only way I could think of is this:

import os

os.system('title kill_window')
os.system(f'taskkill /f /fi "WINDOWTITLE eq kill_window"')

Basically, this sets the title of the cmd window to something unique (eg. kill_window), and then uses the taskkill command to search through and kill any processes with that name.

Not the answer you're looking for? Browse other questions tagged or ask your own question.