-4

I am trying to make a batch file that asks questions then uses the variables to make a html file. Is there a way to replace characters WITHIN COMMAND LINE with the stored variables?

I am making my batch file have a very short HTML template with the basics (font-size, colour) and I want the user to be able to choose the font size and colour then have the batch file output the completed template as a HTML. Heres a bit of my bat file. How do I replace the %%% in a cmd environment?

<html><body>
Hello 
</span>NAME HERE

<p <span style='font-size:%%%pt'>

<span style='color:%%%'>

</span></p></body></html>"
AB147
  • 9
  • 3
  • Possible duplicate of [How can you find and replace text in a file using the Windows command-line environment?](https://stackoverflow.com/questions/60034/how-can-you-find-and-replace-text-in-a-file-using-the-windows-command-line-envir) – Lars May 07 '18 at 21:40
  • Recommend you take the [tour] and read [Ask]. Batch scripts are not a good match for processing html and xml due to the many `<` `>` characters. – jwdonahue May 07 '18 at 22:08

1 Answers1

0

You have to escape all <> with a caret in a batch, otherwise this is trivial and should be no problem - even for beginners.

:: Q:\Test\2018\05\08\SO_50222677.cmd
@Echo off&SetLocal
Set /P "_FileName=FileName  :"
Set /P     "_Size=Size in pt:"
Set /P    "_Color=html color:"
Set /p     "_Name=Hello name:"

(   Echo:^<html^>^<body^>
    Echo:Hello 
    Echo:^</span^>%_NAME%
    Echo:
    Echo:^<p ^<span style='font-size:%_Size%pt'^>
    Echo:
    Echo:^<span style='color:%_Color%'^>
    Echo:
    Echo:^</span^>^</p^>^</body^>^</html^>"
) > "%_FileName%"
  • It may be trivial but I couldn't find/didn't know what to look for the right help online. Thank you so much. – AB147 May 08 '18 at 01:25