是否可以通过&传递变量?作为批处理文件中的参数

时间:2014-04-02 12:57:24

标签: batch-file

我想通过&在一个值作为参数。在下面的示例代码中,我可以成功回显FILE_NAME,但如何将其作为参数传递给:TEE标签?

@ECHO OFF
CLS
SETLOCAL ENABLEDELAYEDEXPANSION

SET FILE_PATH=C:\TEMP\FILE^&NAME.TXT

REM THIS WORKS
ECHO !FILE_PATH!

REM THIS DOES NOT WORK
CALL :TEE !FILE_PATH!

GOTO :EOF

:TEE
FOR /F "TOKENS=*" %%Z IN ("%*") DO (
ECHO %%Z
     >  CON ECHO.%%Z
     >> "!LOG_FILE!" ECHO.%%Z
     GOTO :EOF
)
GOTO :EOF

1 个答案:

答案 0 :(得分:3)

@ECHO OFF
CLS
SETLOCAL ENABLEDELAYEDEXPANSION

SET FILE_PATH=C:\TEMP\FILE^&NAME.TXT

REM THIS WORKS
ECHO !FILE_PATH!

REM THIS DOES NOT WORK
CALL :TEE "%FILE_PATH%"

GOTO :EOF

:TEE
FOR /F "TOKENS=* USEBACKQ" %%Z IN ('%*') DO (
ECHO %%~Z
     >  CON ECHO.%%~Z
     >> "!LOG_FILE!" ECHO.%%~Z
     GOTO :EOF
)
GOTO :EOF

是的,它是 - 这是单程