2016-07-27 133 views
1

在一般情况下,我们可以使用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.systemsubprocess.Popen执行?

+1

消息来自shell,而不是来自Python。 – cdarke

+0

你有哪个版本的Python?那你的操作系统呢? – Giordano

+0

可能重复的[是否有可能从Python内部杀死Windows上的进程?](http://stackoverflow.com/questions/6278847/is-it-possible-to-kill-a-process-on-windows- from-within-python) –

回答

2

我已经找到了根本原因:

我的Python是32位的,而我的电脑是Windows7的64位,所以Python的os.system无法运行tskill。如果我使用Python 64位,则一切正常。

0

使用的taskkill,它可以做几乎所有的TSKILL

但是,如果你要坚持你的脚本/代码tskill.exe。请从提升的命令提示符运行脚本。 (右键单击cmd.exe的运行它为管理员)

os.system('c:\windows\system32\tskill.exe 8684')