How do I add a carriage return before a new hosts file entry (if an entry already exists)?

How do I add a carriage return before a new hosts file entry (if an entry already exists) ?

This appends the entry to the last entry in the hosts file (with no space) -

waithidden cmd.exe /C echo {"%0d%0a12.13.14.15 test.test.test.test1"} >> {(pathname of system folder as string & "\drivers\etc\hosts")}

This doesn’t add the entry at all -

waithidden cmd.exe /C echo {"%0d%0a12.13.14.15 test.test.test.test1"} >> {(pathname of system folder as string & "\drivers\etc\hosts")}

( Originally posted here: Appending entry into the HOSTS file )

This will do it via action script

delete __createfile
createfile until EOF
{concatenation "%0D%0A" of lines of file "C:\Windows\System32\drivers\etc\hosts"}
12.13.14.15 test.test.test.test1
EOF
delete "C:\Windows\System32\drivers\etc\hosts"
move __createfile "C:\Windows\System32\drivers\etc\hosts"

thanks, I’ve made a few edits -

delete __createfile
createfile until EOF
{concatenation "%0D%0A" of lines of file (pathname of system folder as string & "\drivers\etc\hosts")}
12.13.14.15 test.test.test.test1
EOF
delete {(pathname of system folder as string & "\drivers\etc\hosts")}
move __createfile {(pathname of system folder as string & "\drivers\etc\hosts")}
2 Likes

I’ve seen using move instead of copy do some odd things with permissions. It shouldn’t be an issue in this case, but something to keep in mind in others.


Sorry for the bump 2 years later, but I wanted to add this:

Related: