cmd terminal - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: cmd terminal (/thread-41939.html) |
cmd terminal - Raysz - Apr-11-2024 So I have the simple program that I made in Python tkinter It opens up a cmd window and executes sfc /scannow What I'm trying to figure out is if I click on the X at the top right corner I get a ^C how do I prevent this, how do I close the window the proper way I tried to put it in a try block with a keyboard interruption and that didn't seem to work I tried several different ways to use kill but I am unclear on how it's supposed to work def sfc_scannow(): # sfc / scannow if not pyuac.isUserAdmin(): statusbar.set('Access is denied, you are not an admin') root.after(5000, lambda: statusbar.set('')) # print('okM') # for testing else: sfc_scannow_data() def sfc_scannow_data(): subprocess.Popen("start /wait sfc /scannow", shell=True) RE: cmd terminal - deanhystad - Apr-11-2024 If you don't display the cmd window it cannot be closed. Do you want the window? If so, why? RE: cmd terminal - Raysz - Apr-12-2024 (Apr-11-2024, 08:42 PM)deanhystad Wrote: If you don't display the cmd window it cannot be closed. Do you want the window? If so, why? When I execute the sfc /scannow it does open up the window then proceeds to check the system out but if I close the window using the X at the top right corner I get ^C which if I am correct that represents control C so how do I properly close this window RE: cmd terminal - deanhystad - Apr-12-2024 But do you need to open the window at all? You can do the scan without opening a cmd window. You do this: def sfc_scannow_data(): subprocess.Popen(["sfc", "/scannow"])If you want to display output from the command you can get that from the Popen call and display it in the tkinter window. RE: cmd terminal - Raysz - Apr-12-2024 (Apr-12-2024, 11:56 AM)deanhystad Wrote: But do you need to open the window at all? You can do the scan without opening a cmd window. You do this: Interesting concept I didn't think about that I will certainly give it a try RE: cmd terminal - Rice23 - Apr-22-2024 If one wishes to display the output from the command, how can it be obtained from the Popen call and displayed in a tkinter window? RE: cmd terminal - Gribouillis - Apr-22-2024 (Apr-22-2024, 04:30 AM)Rice23 Wrote: If one wishes to display the output from the command, how can it be obtained from the Popen call and displayed in a tkinter window?You can write process = subprocess.run(['command', 'arg', 'arg'], capture_output=True, encoding='utf8') print(process.stdout) print(process.stderr)Then instead of printing the strings process.stdout and process.stderr, you can insert them in a Tkinter Text widget for example. |