Two issues: You are echoing "%target_string% " which has two trailing
spaces
before the pipe character.
"if %errorlevel% == 0" should really be "if %errorlevel% EQU 0" or
"if not errorlevel 1" or "if %errorlevel%.==0." to avoid ambiguity or
errors.- Hide quoted text -
- Show quoted text -
Thank you. You are quite right. It was the space before the pipe
character that was causing the problem. I had also tested by
directing the target string into a disk file i.e.
echo %target_string > input.txt
but in exactely the same manner I was inadvertently appending a SPACE
at the end of the line.
Its a relief to have a simple explanation to what was a perplexing
problem. I will be far more careful typing in batch code in the future
===> glad you got that one sorted out. What I was going to suggest was that
the caret "^" has also a special meaning for cmd.exe: "literal next
character". Basically, it plus the following character are replaced with
just the following character, bypassing intermediate interpretation, i.e.:
for /f "delims=~" %%X in ('dir C:\ | find ":" ') do echo %%X
will generate a "| was unexpected at this time" error, whereas this:
for /f "delims=~" %%X in ('dir C:\ ^| find ":" ') do echo %%X
doesn't. I was concerned that perhaps cmd.exe was converting ["|abc$"] into
["abc$"] before passing the result to findstr.exe.
/Al