How to save the output result of a Python script to a txt file?

0

Script showing saved wifi passwords:

import subprocess
data = subprocess.check_output(['netsh', 'wlan', 'show', 'profiles']).decode('utf-8', errors="backslashreplace").split('\n')
profiles = [i.split(":") [1] [1:-1] for i in data if "Todos os Perfis de Usu\xa0rios" in i]
for i in profiles:
    try:
        results = subprocess.check_output(['netsh', 'wlan', 'show', 'profile', i, 'key=clear']).decode('utf-8', errors="backslashreplace).split('\n')
        results = [b.split(":") [1] [1:-1] for b in results if "Conte\xa3do da Chave" in b]
        try:
            print ("{:<30}|  {:<}".format(i, results[0]))
        except IndexError:
            print ("{:<30}|  {:<}".format(i, "")
    except subprocess.CalledProcessError:
        print ("{:<30}|  {:<}".format(i, "ENCODING ERROR"))
input("")

Output result:

HowtosavetheoutputresulttoaTXTdocumentwithouthavingtodisplaythePRINTinthe"Shell"?

    
asked by anonymous 05.12.2018 / 01:18

0 answers