我正在尝试从批处理文件中调用命令,该批处理文件正在从文件中读取行。
这工作正常,除非该行包含重定向字符>。
有没有办法告诉call转义这个字符,或者在 for 循环的内容中替换它?
我看过setlocal enabledelayedexpansionand (当调用更新为使用!它仍然不起作用)。
set /p status=<%tmp_file%
for /f "delims=*" %%a in (%tmp_file%) do (
echo "%%a"
call check.bat "%%a"
echo.
if not "%errorlevel%" == "0" do exit /b 1
)
这会产生以下输出(当check.batecho's时%1)
"a"
"a"
"b -> b"
"b -"
我尝试在其中替换>,%%a但我不完全确定如何实现,每次尝试时,它都会产生一个空字符串,即
set line=%a:^>=¬%
编辑 1更多说明(如果设置为变量,然后使用该变量,
似乎只有这种情况)?:%1
check.bat:
set rawinput=%1
set input=%~1
echo %1
echo "%rawinput%"
echo "%input%"
echo.
这会产生以下输出,尽管我不太确定为什么设置%1变量会导致它破坏值?
"a"
"a"
""a""
"a"
"b -> b"
"b -> b"
"b -"
有趣b -> b的是只输出2次,echo "%rawinput%"根本没有显示。两者echo "%input%"和echo "%rawinput%"都在写入一个名为b.
这意味着check.batforb -> b必须解释为:
echo "b -> b"
echo ""b -> b""
echo "b -> b" REM - this is what 'should' be happening, however does appear to be the case, as it writes '' to a file named b
echo.
如果有人可以阐明为什么echo "b -> b"批处理文件中的行为似乎没有表现,将不胜感激。