On Sun, 20 Nov 2022 21:04:33 +0100, R.Wieser wrote:
>
> Ive put a few lines of text ("hello&world", "&foo", "bar&") in a file,
> retrieved those lines and than called your ":sub" with it like this :
>
> for /f %%i in (words.txt) do call :sub %%i
>
> , but for some reason your ":sub" was not called for the first two (though
> no error or other output), but it was for the third/last line. IOW, I could
> not test it either ...
CALL would force the command line to be parsed and expanded twice.
On the second command line processing, the `%%i` is already expanded, so it
is or should be treated as a command separator. However, it seems that
there's a bug on the second command line processing, since it may cancel the
CALL command execution. Below is a simple demo of this bug.
@echo off
setlocal
set a=hello^&world
set b=%%a%%
rem output: abc "hello&world"
call echo abc "%b%"
rem expected output: hello&world
rem but since `%b%` is not quoted, after expansion,
rem the `&` should be treated as a command reparator.
rem but it cancels the whole command line.
call echo abc %b%
echo end
> I also tried a line (in the textfile) with an embedded doublequote. The it
> caused the "set /p" to wait for input again. And ofcourse the simple "echo
> %1" had no problems with it.
Chances are that, your SET /P is like this.
set /p a="%1"<nul
Since the paramater is already quoted, the parsed command line would be like
below, where the quotes from SET /P are paired with the ones from the
contents of `%1`. Making the `hello&world` unquoted, and the `&` character
be treated as command separator.
So the quotes from the content of `%1` should be stripped first. i.e.
set /p a="%~1"<nul