Okay, finally after reading this article about proper quoting of command line arguments, I came to this solution:
set comm=%comm: =^^ %
set comm=%comm:"=""%
This code is to be placed below your set /p ...
line and before your if...
condition. It precedes all spaces by the caret sign (1st line) and doubles all double quotes (2nd line). By this, no one of these characters will be treated as poison characters anymore.
Explanation
The caret sign (^) is used by the cmd.exe command line interpreter as the so called "line continuation character", which means to take the next character literally rather than interpret its (possibly) special meaning (including the special meaning of space characters to split up the commands on a command line).
From other discussions here in this thread: The square brackets "[]" are not handled as any special character at all. This is why it still fails when there are spaces inside.
In contrast to this, double quotes are indeed treated as special characters with the meaning that after the first found double quote the interpreter will interpret all upcoming text literally. But the interpreter will do the same only until it finds the next double quote, which is why the if
evaluation still fails on unbalanced double quotes. To prevent this, each double quote needs also to be doubled itself.
Hope this helps now.
%comm%
allowed to have spaces?