我想用Python脚本在Windows10上运行并关闭资源管理器。但我不能。 subprocess.Popen.terminate()不关闭资源管理器。怎么了
import subprocess
folder = r'C:\Users\issy\Documents'
pidcheck = 'tasklist | find "explorer"'
subprocess.check_output(pidcheck, shell=True)
Out[6]: b'explorer.exe 18568 Console 3 148,416 K\r\n'
Popen_explorer = subprocess.Popen(['explorer',folder])
Popen_explorer.pid
Out[8]: 2176
subprocess.check_output(pidcheck, shell=True)
Out[9]: b'explorer.exe 18568 Console 3 150,416 K\r\n explorer.exe 11732 Console 3 64,696 K\r\n'
# pid is different. 11732 is true. subprocess.Popen.pid shows wrong id 2176.
Popen_explorer.terminate()
# explorer does not close.
目前没有回答
相关问题 更多 >
编程相关推荐