Running Python file in administrator command prompt doesn't show any output or error

Viewed 17

1.I'm writing a Python program for websiteblocking, but while running it, I got an PermissionError. So I ran the script in an elevated command prompt, but now it doesn't show any output or error. The cursor just keeps blinking.

enter image description here

  1. this is program when I am running using administrator cmd because of error ocurs mention at the bottom of code
    import datetime
    
    import time
    end_time=datetime.datetime(2022,9,22)
    site_block=["www.wscubetech.com","www.facebook.com"]
    host_path="C:/Windows/System32/drivers/etc/hosts"
    redirect="127.0.0.1"
    while True:
        if datetime.datetime.now()<end_time:
            print("Start Blocking..")
            with open(host_path,"r+") as host_file:
                content = host_file.read()
                for website in site_block:
                    if website not in content:
                        host_file.write(redirect+" "+website+"\n")
                    else:
                        pass
        else:
             with open(host_path,"r+") as host_file:
                    content = host_file.readlines()
                    host_file.seek(0)
                    for lines in content:
                        if not any(website in lines for website in site_block):
                            host_file.write(lines)
                    host_file.truncate()
             time.sleep(5)

3.output(error)

    PermissionError                           Traceback (most recent call last)
    Input In [15], in <cell line: 8>()
    

      9 if datetime.datetime.now()<end_time:
         10     print("Start Blocking..")
    ---> 11     with open(host_path,"r+") as host_file:
         12         content = host_file.read()
         13         for website in site_block:
    
    PermissionError: [Errno 13] Permission denied: 'C:/Windows/System32/drivers/etc/hosts'
0 Answers
Related