一般情况下,我们可以使用Python来执行Windows的cmd命令,例如:
os.system('ipconfig')
但是我发现tskill
不能被Python执行,如果我使用:
os.system('tskill 8684')
要通过 pid 杀死进程,Python 将显示 cmd 的错误:
'tskill' is not recognized as an internal or external command, operable program or batch file.
但是如果我使用cmd来运行命令,效果很好。
据我所知tskill.exe
位于C:\Windows\System32,但该路径不在Python的环境变量中。可能是这个原因,但是ipconfig.exe
也在System32中,可以执行。
那么为什么tskill
不能被os.system或subprocess.Popen执行呢?
最佳答案
我找到了根本原因:
我的Python是32位的,而我的PC是Windows7 64位的,所以Python的os.system
无法运行tskill
。如果我使用 Python 64 位,则一切正常。
关于python - 为什么Python无法执行cmd命令 'tskill'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38610730/