开发者

Escaping strings in a Windows Batch For Loop

开发者 https://www.devze.com 2023-04-03 02:20 出处:网络
I\'m having problems with the following code: FOR /f \"tokens=*\" %%A in (%MYFILE_PAT开发者_开发问答H%) do (

I'm having problems with the following code:

FOR /f "tokens=*" %%A in (%MYFILE_PAT开发者_开发问答H%) do (
    [other stuff]
    echo %%A>> "%MYFILE_PATH%.scratch"
)

The file being read has XML in it and when < and > signs are read, the script throws errors. How can I escape the contents of %%A to safely echo to the output file? I don't want to put double quotes around it since it will then echo the quotes too.

Thanks


FOR /f "tokens=*" %%A in (%MYFILE_PATH%) do (
    [other stuff]
    (echo %%A)>>"%MYFILE_PATH%.scratch"
)

When appending the contents of %%A into another file, all that you are essentially doing is copying the file.

EDIT

 FOR /f "tokens=* delims=" %%A in (%MYFILE_PATH%) do (
    [other stuff]
    (echo %%A)>>"%MYFILE_PATH%.scratch"
)
0

精彩评论

暂无评论...
验证码 换一张
取 消