Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
cmd terminal
#1
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)
Reply
#2
If you don't display the cmd window it cannot be closed. Do you want the window? If so, why?
Reply
#3
(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
Reply
#4
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.
Reply
#5
(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:
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.

Interesting concept I didn't think about that I will certainly give it a try
Reply
#6
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?
Reply
#7
(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.
« We can solve any problem by introducing an extra level of indirection »
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020