标题: [文本处理] 批处理怎样判断文本,高于这个数值或者小于这个,执行命令? [打印本页]
作者: zdqzdqzdq 时间: 2012-6-22 03:40 标题: 批处理怎样判断文本,高于这个数值或者小于这个,执行命令?
通过这个命令
tasklist /v>123.txt
得到 123.txt文本内容如下
图像名 PID 会话名 会话# 内存使用 状态 用户名 CPU 时间 窗口标题
========================= ====== ================ ======== ============ =============== ================================================== ============ ========================================================================
System Idle Process 0 Console 0 28 K Running NT AUTHORITY\SYSTEM 14:09:56 暂缺
System 4 Console 0 304 K Running NT AUTHORITY\SYSTEM 0:01:20 暂缺
smss.exe 460 Console 0 404 K Running NT AUTHORITY\SYSTEM 0:00:00 暂缺
csrss.exe 972 Console 0 8,220 K Running NT AUTHORITY\SYSTEM 0:00:45 暂缺
winlogon.exe 1012 Console 0 11,216 K Running NT AUTHORITY\SYSTEM 0:00:01 NetDDE Agent
services.exe 1056 Console 0 9,716 K Running NT AUTHORITY\SYSTEM 0:00:14 暂缺
lsass.exe 1068 Console 0 1,364 K Running NT AUTHORITY\SYSTEM 0:00:11 暂缺
svchost.exe 1244 Console 0 5,500 K Running NT AUTHORITY\SYSTEM 0:00:00 暂缺
svchost.exe 1292 Console 0 4,216 K Running NT AUTHORITY\NETWORK SERVICE 0:00:03 暂缺
svchost.exe 1324 Console 0 22,584 K Running NT AUTHORITY\SYSTEM 0:00:07 暂缺
svchost.exe 1436 Console 0 3,244 K Running NT AUTHORITY\LOCAL SERVICE 0:00:00 暂缺
spoolsv.exe 1804 Console 0 4,936 K Running NT AUTHORITY\SYSTEM 0:00:00 暂缺
acs.exe 1884 Console 0 9,896 K Running NT AUTHORITY\SYSTEM 0:00:00 暂缺
AlipaySecSvc.exe 1912 Console 0 4,776 K Running NT AUTHORITY\SYSTEM 0:00:00 暂缺
winvnc4.exe 2020 Console 0 198,068 K Running NT AUTHORITY\SYSTEM 0:00:00 winvnc::IPC_Interface
wscntfy.exe 1532 Console 0 2,624 K Running IDC-4C0559B01D7\zdq 0:00:00 暂缺
然后通过搜索提取 某exe的行,,,,第5列,,,第5列是 进程的内存使用情况 ....比如已经提取出来EXE的内存使用情况是 198,068
每次提取 进程使用情况的值,,,,然后进行判断,,, 如果某EXE内存使用情况低于100,000 或者低于11,216 就使用某DOS命令 高于100,000 或者11,216就退出,,,,
请高手们 出几个列子啊
另外再请教一个判断,,,检测指定判断当前目录的 某TXT的 KB大小,,,, 如果KB大小 小于多少KB 就执行 DOS命令 大于就退出
另外再请教一个判断,,,检测指定判断当前目录的 某TXT的 KB大小,,,, 如果KB大小 小于多少KB 就执行 DOS命令 大于就退出
另外再请教一个判断,,,检测指定判断当前目录的 某TXT的 KB大小,,,, 如果KB大小 小于多少KB 就执行 DOS命令 大于就退出
作者: ufwuwlgah 时间: 2012-6-22 04:35
这个是我刚学批处理时做的第一个批处理监控进程,你自己改一下。。。复制代码
作者: zdqzdqzdq 时间: 2012-6-22 05:33
回复 2# ufwuwlgah
好象和这个没关系吧
作者: apang 时间: 2012-6-22 11:35
- @echo off
- set "process=winlogon.exe"
- for /f "delims=" %%a in ('tasklist /v /fo csv^|findstr /i "%process%"') do (
- call :11 %%a
- )
- goto :eof
-
- :11
- set "m=%~5"
- set "m=%m: k=%"
- set "m=%m:,=%"
- if %m% lss 100000 echo %~5&pause
复制代码
作者: zdqzdqzdq 时间: 2012-6-22 16:21
回复 4# apang
万分感谢
作者: poter 时间: 2012-6-22 21:21
@echo off
setlocal enableDelayedExpansion
for /f "tokens=*" %%i in ('findstr /i "console" 123.txt') do (
set str=%%i&set "str=!str:*Console=!"
for /f "tokens=2" %%j in ("!str!") do (
set str=%%j&set "str=!str:,=!"
if !str! leq 11216 echo "start 某条命令"
if !str! geq 11216 echo "kill 某个进程"
)
)
作者: zdqzdqzdq 时间: 2012-6-23 02:29
回复 4# apang
好象这个IF命令只可以比较3个字母的 大小 怎么可以比较3个字母以上的 大小值
作者: terse 时间: 2012-6-23 03:50
仅对你- @echo off
- set "process=winlogon.exe"
- for /f "delims=" %%i in ('tasklist /nh /fo csv /FI "IMAGENAME eq %process%" /FI "MEMUSAGE lt 10000" 2^>nul') do (
- FOR %%j in (%%i) do set "M=%%~j"
- )
- if defined M (echo %process% 内存使用 %M%) else exit
- pause
复制代码
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |