Batch file 批处理脚本忽略%ERRORLEVEL%或使用以前设置的

Batch file 批处理脚本忽略%ERRORLEVEL%或使用以前设置的,batch-file,process,errorlevel,Batch File,Process,Errorlevel,我编写了一个批处理脚本,以确定特定进程是否在计算机上运行: for /f %%a in (computers.txt) do (     PsList.exe \\%%a -e "process" > result.txt     Find /i "found" < result.txt     IF "%ERRORLEVEL%" == "0" echo %%a >> Computers_without_process.csv ) 用于

我编写了一个批处理脚本,以确定特定进程是否在计算机上运行:

    for /f %%a in (computers.txt) do (
        PsList.exe \\%%a -e "process" > result.txt
        Find /i "found" < result.txt
        IF "%ERRORLEVEL%" == "0" echo %%a >> Computers_without_process.csv
)
用于(computers.txt)中的/f%%a(
PsList.exe\\%%a-e“进程”>result.txt
查找/i“找到”>计算机没有\u process.csv
)
我确实找到了/I“找到了”,因为如果找不到进程,它会返回:“在computername上找不到进程…”

如果找到该进程,它将返回其信息。而且字符串“found”不在那里

我什么都试过了

谢谢你的帮助

你需要

setlocal enableDelayedExpansion    
for /f %%a in (computers.txt) do (
        PsList.exe \\%%a -e "process" > result.txt
        Find /i "found" < result.txt
        IF "!ERRORLEVEL!" == "0" echo %%a >> Computers_without_process.csv
)
setlocal enableDelayedExpansion    
for /f %%a in (computers.txt) do (
        PsList.exe \\%%a -e "process" | Find /i "found" >nul 2>nul && (
           echo %%a >> Computers_without_process.csv
         )
)