Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在编写一个需要能够杀死某些进程的程序。我目前正在使用的两条线路;但是,第二行os.system(task)在结束进程时会在瞬间启动命令提示符。是否有任何不启动命令提示符的等效行?
片段:
task = 'taskkill /im ' + taskname + ' /f' os.system(task)
如果您无法猜到,这是在 Windows 7 中。
尝试使用subprocess.check_call而不是os.system. 这不会在控制台窗口中启动该进程。
subprocess.check_call
os.system
import subprocess taskname = '...' task = 'taskkill /im ' + taskname + ' /f' subprocess.check_call(task, shell=True)