为什么这个管道在 for 循环中不起作用
Why is this pipe not working inside a for loop
当我运行代码时,它输出FIND: Parameter format not correct
和The process tried to write to a nonexistent pipe.
。由此,我很确定 for 循环无法处理管道 and/or 重定向。我不确定从这里开始做什么,我已经在循环外尝试 运行ning 它,并且工作正常,但在循环内它会卡住假人。有谁知道为什么,或者我该如何解决这个问题?
@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
在有人说之前,我知道这不是在文件中查找字符串的最有效方法,但它对我处理的文件大小无关紧要。
type someFile | find word
完全失败,因为查找需要 "word" 引号。
所以解决方案是将您的行更改为
type set_2.txt | find "%%a" > nul
if !errorlevel! EQU 0 (
....
或者更简单
type set_2.txt | find "%%a" > nul || echo %%a not found
当我运行代码时,它输出FIND: Parameter format not correct
和The process tried to write to a nonexistent pipe.
。由此,我很确定 for 循环无法处理管道 and/or 重定向。我不确定从这里开始做什么,我已经在循环外尝试 运行ning 它,并且工作正常,但在循环内它会卡住假人。有谁知道为什么,或者我该如何解决这个问题?
@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
在有人说之前,我知道这不是在文件中查找字符串的最有效方法,但它对我处理的文件大小无关紧要。
type someFile | find word
完全失败,因为查找需要 "word" 引号。
所以解决方案是将您的行更改为
type set_2.txt | find "%%a" > nul
if !errorlevel! EQU 0 (
....
或者更简单
type set_2.txt | find "%%a" > nul || echo %%a not found