Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BATCH - Working with string(< , >) instead of redirection

The last word in every texts in testing.txt is "< /a>", I echo out the the word and it seems to be no problem, but when I echo out in the for loop, cmd gave me this error : "The system cannot find the file specified."
I know the problem is on the "<" and ">" sign, it stands for redirection, that's how the error created. How am I going to make cmd think I'm working with a string instead of redirection?

@echo off
setlocal EnableDelayedExpansion

set "remove_char=< /a>"
echo !remove_char!

for /f "skip=2 tokens=6*" %%a in (testing.txt) do (
    set "string=%%a %%b"
    set string=!string:%remove_char%=!
    echo !string!

)

pause >nul
like image 638
WhatWhereWhen Avatar asked Aug 09 '15 12:08

WhatWhereWhen


1 Answers

If you want to use < and > symbols as variables you have to change them to ^< or ^>

Otherwise they will be treated as Input or Output!

like image 145
5H4D0W Avatar answered Oct 09 '22 01:10

5H4D0W