中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

中国DOS联盟论坛
现在时间是 2026-08-13 00:45
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » 批处理判断进程 查看 1,035 回复 3
楼 主 批处理判断进程 发表于 2009-12-25 17:07 ·  中国 重庆 电信
新手上路
积分 2
发帖 3
注册 2009-12-08 17:17
16年会员
UID 156155
性别 男
状态 离线
@echo off
:cx
tasklist>1.txt
type 1.txt|find "Christmas day.exe">2.txt
set /p c=<2.txt
set a=%c:~0,17%
echo %a%>1.txt
set /p b=<1.txt
if not "%b%"=="Christmas day.exe" goto gb
if "%b%"=="Christmas day.exe" goto cx
:gb
echo 进程不存在
del 1.txt
del 2.txt
pause

我这样来循环判断Christmas day.exe进程时,当先Christmas day.exe,之后,再打开这个文件,然后关闭Christmas day.exe后,发现不会跳转到“进程不存在”这。我要一直检测这个进程,当这个进程退出后就跳转执行另一条命令,该怎么做啊?
2 发表于 2009-12-25 18:34 ·  中国 湖北 荆门 电信
初级用户
★★
积分 186
发帖 117
注册 2006-08-14 14:50
19年会员
UID 60491
状态 离线
@echo off
:loop
tasklist | findstr /i "notepad.exe">nul && call :success || call :failure
pause
goto loop
goto :eof

:success
echo %time%存在!
goto :eof

:failure
echo %time%不存在!
goto :eof
3 发表于 2009-12-25 18:40 ·  中国 湖北 荆门 电信
初级用户
★★
积分 186
发帖 117
注册 2006-08-14 14:50
19年会员
UID 60491
状态 离线
如果进程名中包含空格,则findstr应加上/c参数:tasklist | findstr /ic:"aa aa.exe">nul && call :success || call :failure
更严谨一点应该加上/r和^:
tasklist | findstr /irc:"^aa aa.exe">nul && call :success || call :failure
4 发表于 2009-12-25 19:27 ·  中国 广东 广州 华为云
初级用户
积分 33
发帖 20
注册 2008-10-12 19:14
17年会员
UID 128185
性别 男
状态 离线
@echo off
start x:\Christmas day.exe
goto loop1
:loop1
echo 等待Christmas day.exe
ping 127.1 -n 2 >nul
tasklist|find /i "Christmas day.exe">nul && goto loop2 || goto loop1
:loop2
echo 正在运行Christmas day.exe
ping 127.1 -n 2 >nul
tasklist|find /i "Christmas day.exe">nul && goto loop2 || goto end
:end
call xxx.bat

一个简单的循环判断进程的方法...
我自己一直用这个...
技术烂 写不出好代码..

[ Last edited by zxh17173 on 2009-12-25 at 19:33 ]
论坛跳转: