Reputation: 1362
In general, we can use Python to execute Windows's cmd command, for example:
os.system('ipconfig')
but I find that tskill
can not be executed by Python, if I use:
os.system('tskill 8684')
to kill a process by its pid, Python will show cmd's error:
'tskill' is not recognized as an internal or external command, operable program or batch file.
but it work well if I use cmd to run the command.
As I know tskill.exe
is located in C:\Windows\System32, but this path is not in Python's environment variable. It is maybe the reason, but ipconfig.exe
is also in System32, it can be executed.
So why tskill
can not be executed by os.system or subprocess.Popen?
Upvotes: 2
Views: 2009
Reputation: 1362
I have found the root reason:
My Python is 32-bit, while My PC is Windows7 64-bit, so Python's os.system
can not run tskill
. If I use Python 64-bit instead, everything is OK.
Upvotes: 3
Reputation: 4441
Use taskkill, which can do pretty much everything as tskill
But if you want to stick to tskill.exe in your scripts/code. Please run the scripts from elevated command prompts. (Right click on cmd.exe and run it as administrator)
os.system('c:\windows\system32\tskill.exe 8684')
Upvotes: 1