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. 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.

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

Comments

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.