在一般情况下,我们可以使用Python来执行的Windows的cmd命令,例如:为什么Python不能执行cmd命令'tskill'?
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执行?
消息来自shell,而不是来自Python。 – cdarke
你有哪个版本的Python?那你的操作系统呢? – Giordano
可能重复的[是否有可能从Python内部杀死Windows上的进程?](http://stackoverflow.com/questions/6278847/is-it-possible-to-kill-a-process-on-windows- from-within-python) –