首页 文章

为什么这个管道在for循环中不起作用

提问于
浏览
1

当我运行代码时,它输出 FIND: Parameter format not correctThe process tried to write to a nonexistent pipe. . 由此,我'm pretty sure the for loop can't处理管道和/或重定向 . 我已经尝试在循环外运行它,并且工作正常,但在循环内它会丢弃假人 . 有谁知道为什么,或者我如何解决这个问题?

@ECHO OFF

setlocal enabledelayedexpansion
for /F "tokens=*" %%a in (set_1.txt) do (
    type set_2.txt | find %%a > nul
    if !errorlevel! EQU 1 (
        echo %%a
    )
) 

endlocal
pause

在任何人说出来之前,我知道这不是在文件中查找字符串的最有效方法,但是对于我正在处理的文件大小并不重要 .

1 回答

  • 4

    type someFile | find word 完全失败,因为find需要"word"引号 .

    因此,解决方案是将您的 生产环境 线更改为

    type set_2.txt | find "%%a" > nul
    if !errorlevel! EQU 0 (
         ....
    

    甚至更简单

    type set_2.txt | find "%%a" > nul || echo %%a not found
    

相关问题