Board logo

标题: [代码合集] 求解 批处理判断多个进程问题 [打印本页]

作者: yofee    时间: 2012-10-23 23:28     标题: 求解 批处理判断多个进程问题

(一)若系统进程中同时存在a.exe和b.exe 就goto exit (二) 若系统进程中同时不存在a.exe和b.exe 或者只存在其当中的一个进程 就goto next  。我参照资料写了一个小P 代码如下:
tasklist |find /i "a.exe b.exe"
if %errorlevel%==0 (goto exit) else (goto next)

但不知错在哪里 运行时无论这2个进程存不存在,它都跳到goto next 继续执行指令

求高手指正我错在哪里 ,或麻烦高手给我重写一个 谢谢
作者: forfiles    时间: 2012-10-24 00:32

  1. tasklist |find /i "a.exe" |find /i "b.exe" && goto exit
  2. goto next
复制代码

作者: wc726842270    时间: 2012-10-24 05:43

略微改了一下
  1. (((tasklist|find /i "a.exe")&&(tasklist|find /i "b.exe"))&&goto exit)||(tasklist|findstr /I "[ab].exe")&&goto next
复制代码
没有实验过
作者: yofee    时间: 2012-10-24 07:29

回复 2# forfiles


    这位好人写的代码,测试发现,两个进程同时存在是也是跳到goto next  ,不能正确跳到 goto exit 指令上
作者: yofee    时间: 2012-10-24 07:32

回复 3# wc726842270


    嗯嗯 测试没出错很好   ,能不能代码简单点
作者: forfiles    时间: 2012-10-24 10:32

回复 4# yofee


    把的完整测试代码和测试结果贴出来看看
作者: wc726842270    时间: 2012-10-24 16:30

落了一点
  1. (((tasklist|find /i "a.exe")&&(tasklist|find /i "b.exe"))&&goto exit)||goto next
复制代码

作者: 韩立    时间: 2012-10-24 22:01

回复 7# wc726842270
存在部分匹配问题,如media.exe存在意味着a.exe也存在,不过日常一般不会出现这种问题。




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2