Windows批处理中"fuser -k< folder>"的等效项是什么? [英] What is the Windows batch equivalent of "fuser -k <folder>"?

查看:78
本文介绍了Windows批处理中"fuser -k< folder>"的等效项是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Unix shell脚本,它将杀死正在访问文件夹的所有进程:

I have a Unix shell script which will kill any process that is accessing a folder:

fuser -k ..\logs\*

是否存在与此等效的Windows批处理脚本?我知道TASKKILL,但不确定是否能满足我的需求.有谁知道Windows Shell可以做到这一点吗?

Is there a Windows batch script equivalent to this? I am aware of TASKKILL but I'm not sure if it will do what I need. Does anyone know if this is possible with Windows shell?

推荐答案

不是内置工具(没有可以枚举句柄的东西),但是您可以使用Sysinternals

Not with built-in tools (there is nothing that can enumerate handles), but you can use the Sysinternals Handle tool to get a list of the PIDs that have open handles on a file. You can then parse the output with FOR /F and use TASKKILL to end the processes.

示例:

for /f "skip=4 tokens=3" %i in ('handle ..\logs\') do taskkill /pid %i

skip = 4 跳过Handle输出中的版权信息,而 tokens = 3 从输出的每一行中选择PID.其余的不言自明.

skip=4 skips the copyright information in Handle's output and tokens=3 picks out the PID from each line of output. The rest are self-explanatory.

这篇关于Windows批处理中"fuser -k< folder>"的等效项是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆