I am trying to call a command from a batch file which is reading in lines from a file.
This is working correctly, except for when the line contains the redirection character >.
Is there a way to tell call to escape this character, or to replace it within the content of the for loop?
I've looked at setlocal enabledelayedexpansion and (when the call is updated to use ! it still doesn't work).
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
)
This produces the following output (when check.bat echo's %1)
"a"
"a"
"b -> b"
"b -"
I've tried to replace > within %%a but I'm not entirely sure how this can be achieved, each time i try, it yields an empty string, i.e.
set line=%a:^>=¬%
EDIT 1
Some more clarification (it appears to only be the case if %1 is set to a variable, and then that variable is used)?:
check.bat:
set rawinput=%1
set input=%~1
echo %1
echo "%rawinput%"
echo "%input%"
echo.
This yields the following output, although im not quite sure why setting %1 to a variable causes it to mangle the value?
"a"
"a"
""a""
"a"
"b -> b"
"b -> b"
"b -"
Interestingly b -> b is only output 2 times, echo "%rawinput%" is not showing at all.
Both echo "%input%" and echo "%rawinput%" are writing to a file named b.
This means that the check.bat for b -> b must be interpreted as:
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.
If anyone can shed light on why echo "b -> b" in a batch file does not appear to be behaving it would be greatly appreciated.
>so it doesn't need escaping. I suspect either your code or your results is different than what you posted, or else check.bat is more complicated than you describe.echo "%%a"yields the first line in each pair, incheck.batthe only line isecho %1which yields the second line in each pair. As such the>is being lost/used somewhere.aandb -> b(no quotes in file). Your IF statement is messed up, but other than that it works fine. Both lines printed out just fine by check.bat. I do not get the results you show. There must be something about your situation or your code that you are not telling us. If your file contains quoted"b -> b", thenecho "%%a"should produce""a"", and check.bat should create a file named "b" containing""b -.