'How to suppress TASKILL output in python os module

I am trying to create a close button for my tkinter application without using the sys module. I implemented this:

os.system("TASKKILL /F /IM main.exe")

and converted my program into an exe using Nuitka. Even though I'm using --windows-disable-console while creating the exe with Nuitka, it creates a CLI window after the close button is pressed and outputs "SUCCESS: The process "main.exe" with PID (it shows a different number each time) has been terminated." I tried using py2exe as well to convert it but it does the same thing even though i specify that it is a gui application in my setup.py file. How do I prevent it from creating the CLI window and outputting the success message? I've been trying to figure this out for days but I haven't figured out anything which actually works.



Solution 1:[1]

You are suppressing the PROGRAM output with --windows-diable-console. To disable the output from hte shell, you would have to use the subprocess module

import subprocess
execution_commands_to_be_put_in_popen_to_run = subprocess.Popen(['TASKKILL', '/F', '/IM', 'main.exe'], stdout=subprocess.PIPE, stdin=subprocess.STDOUT, shell=True)
print(execution_commands_to_be_put_in_popen_to_run.stdout.read())

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1