2

How do I add following string to batch file for add it to a file?

<VirtualHost *:80>
    ServerAdmin webmaster@mydomain.dev
    DocumentRoot "J:\repo\mydomain"
    ServerName mydomain.dev
    ErrorLog "logs/mydomain.dev-error.log"
    CustomLog "logs/mydomain.dev-access.log" common
    <Directory "J:\repo\mydomain">
        Order allow,deny
        Allow from all
        Require all granted
    </Directory>
</VirtualHost>

This is what I'm trying to achieve

@echo off
set /p DomName=Enter Domain Name: 
Echo "<VirtualHost *:80>
        ServerAdmin webmaster@mydomain.dev
        DocumentRoot "J:\repo\mydomain"
        ServerName mydomain.dev
        ErrorLog "logs/mydomain.dev-error.log"
        CustomLog "logs/mydomain.dev-access.log" common
        <Directory "J:\repo\mydomain">
            Order allow,deny
            Allow from all
            Require all granted
        </Directory>
    </VirtualHost>" >> "J:\xampp\apache\conf\extra\httpd-vhosts.conf"
:End

I want to replace "DomName" variable inside the string.

Thank you!!!

Achintha Samindika
  • 1,944
  • 1
  • 20
  • 31

1 Answers1

4

You need to Echo each line individually.

Simply use %domname% where you want to substitute the inputted text.

If you use the syntax

(
 echo something
 echo something else
)>somefilename

then a new file will be created containing the text that would have been echoed. If you want to append to anexisting file, use >> in place of >

You need to "escape" some characters which have special meaning to batch. If you want a literal > you need to code ^> if you want the literal text to be produced. Same comment for <

Magoo
  • 77,302
  • 8
  • 62
  • 84