1

I'm writing a program that needs to be able to kill certain processes. The two lines I'm currently using work; however, the second line os.system(task) launches command prompt for a split second whilst it's ending a process. Are there any equivalent lines which do not launch command prompt?

Snippet :

task = 'taskkill /im ' + taskname + ' /f'
os.system(task)

This is in Windows 7 if you couldn't have guessed.

1 Answer 1

3

Try using subprocess.check_call instead of os.system. This won't launch the process in a console window.

import subprocess
taskname = '...'
task = 'taskkill /im ' + taskname + ' /f'
subprocess.check_call(task, shell=True)
Sign up to request clarification or add additional context in comments.

1 Comment

FYI check_call is just a wrapper around call, itself a wrapper around Popen

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.