I have the following batch statement:
for /f "delims=" %%x in (file.lst) do set "offendingfile=%%x"
Although for some really odd reason, when it is called it outputs:
"C:\Windows\calc.exe "
instead of
"C:\Windows\calc.exe"
Since there is a trailin开发者_运维知识库g space, I can't use it properly with any other statements in the batch file, does anyone know why it does this and how to fix this, as its been driving me nuts!
does your file.lst
file has a trailing space after the file name?
I checked this with file.lst having: c:\windows\calc.exe
and the output was correct, but if the file.lst file contains c:\windows\calc.exe<SPACE>
, the output is the same that you are getting (and is the expected output as well).
I believe that the delims=
portion of the for
statement is removing the default behavior of using spaces as delimiters. If you remove that portion, then it should remove the trailing blank:
for /f %%x in (file.lst) do set "offendingfile=%%x"
精彩评论