2

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?

8
  • 1
    The message comes from the shell, not from Python. Commented Jul 27, 2016 at 10:47
  • which version of Python do you have? and what about your OS? Commented Jul 27, 2016 at 10:47
  • Possible duplicate of Is it possible to kill a process on Windows from within Python? Commented Jul 27, 2016 at 10:48
  • You could use taskkill instead. Commented Jul 27, 2016 at 10:49
  • @Jokab I have try taskkill, also can not run. Commented Jul 27, 2016 at 10:56

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.