windows使用脚本杀死python进程
想要使用一行命令关闭python进程,查询得到命令如下
Get-Process | Where-Object { $_.ProcessName -like "*python*" } | Stop-Process -Force
但是此命令直接写在.bat脚本文件中,执行失败,因为此命令需要在powershell下才支持运行,所以需要优化脚本写法:
@echo off
powershell -Command "Get-Process | Where-Object { $_.ProcessName -like \"*python*\" } | Stop-Process -Force"
注意命令中的双引号需要加转义符