TASKKILL在if条件? [英] taskkill in an if condition?

查看:313
本文介绍了TASKKILL在if条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用了任何人的taskkill在Win XP在if条件?我想用它作为看门狗重启程序的情况下,它泄漏内存,并通过在无休止的循环添加它增长得太大。

Has anyone used taskkill on Win XP in an if condition? I want to use it as a watchdog to restart a program in case it leaks memory and grows too big by adding it in an unending loop.

例如用下面的命令,我可以杀的Internet Explorer如果它的内存占用率超过40KB以上(会发生每次):

For example with the following command I can kill Internet Explorer if its memory usage is greater than 40kb (will happen every time):


taskkill /f /fi "imagename eq iexplore.exe" /fi "memusage gt 40" 

我想现在要做的是这样的:

What I want to do now is something like this:


set MY_COMM=taskkill /f /fi "imagename eq iexplore.exe" /fi "memusage gt 40" 
if %MY_COMM% equ 0 ( "C:\Program Files\Internet Explorer\IEXPLORE.EXE" ) else ( echo no internet explorer found  )

TIA,
伯特

TIA, Bert

推荐答案

究竟是你想用这两条线来完成?

What exactly are you trying to accomplish with those two lines?

TASKKILL 将杀死IE考虑指定条件得到满足。返回值不能在你试试吧,虽然方式进行分配。

taskkill will kill IE considering the specified criteria are met. The return value can't be assigned in the way you try it, though.

这是我所看到的,我猜你正在试图杀死IE,之后看一个实例是否被打死,在这种情况下重新启动它。不幸的是,从 TASKKILL 返回值 0 在我们这里有两种情况:标准符合或不符合(在返回值是 128 如果图像名称是无效的,虽然)。因此,我们需要一点点欺骗知道一个进程是否真的被打死:

From what I see I am guessing that you are trying to kill IE and afterwards look whether an instance was killed and restart it in this case. Unfortunately the return value from taskkill is 0 in both cases we're having here: criteria met or not met (the return value is 128 if the image name is invalid, though). So we need a little trickery to know whether a process indeed was killed:

taskkill /f /im iexplore.exe /fi "memusage gt 40" 2>NUL | findstr SUCCESS >NUL

通过管道进入 FINDSTR ,搜索SUCCESS我们可以判断一个进程是否真的被打死。错误级别为 1 的情况下,字符串没有在产量和 0 另有发现。所以,你可以继续如下:

By piping into findstr, searching for "SUCCESS" we can determine whether a process actually was killed. The error level is 1 in case the string wasn't found in the output and 0 otherwise. So you can continue as follows:

if errorlevel 1 ( echo No Internet Explorer was killed ) else ( "%ProgramFiles%\Internet Explorer\iexplore.exe" )

这篇关于TASKKILL在if条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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