Batch File: FOR /F doesn't work if path has spaces

后端 未结 3 2007
粉色の甜心
粉色の甜心 2020-12-06 16:54

This is the problem I\'m having:

@ECHO OFF

REM If this batch file is run in the same directory as \"command.exe\" then the
REM following line will work.
FOR         


        
3条回答
  •  旧时难觅i
    2020-12-06 17:28

    Careful:

    Using 'call' (as shown by Andriy M) seems the safest option.

    I found a case where adding leading and trailing double quotes (as suggested as a possible solution by jeb) has a problem.

    Problem:

    for /f "delims=" %%i in ('""C:\path with spaces\hello.bat" "filename with an & ampersand.jpg""') do ( echo output=%%i )

    cmd.exe's output: & was unexpected at this time.

    Solution:

    for /f "delims=" %%i in ('call "C:\path with spaces\hello.bat" "filename with an & ampersand.jpg"') do ( echo output=%%i )

提交回复
热议问题