Search code examples
batch-filecmdecho

How to echo double quote into file without new line in Batch?


I want to write " sign using Batch in the file.

echo| set /p=""" >> abc.txt

This doesn't work as intended because it gives errors sending data to my file.

Any ideas?


Solution

  • Your idea "three quotes" idea wasn't bad. But due to impaired quotes, the parser doesn't process it right. You have to escape one of them (one of the outer ones - escaping the middle one doesn't work):

    <nul set /p =^""" >> abc.txt
    

    or

    <nul set /p =""^" >> abc.txt
    

    this describes in detail, how cmd does parsing.

    Also I changed echo| set /p... with <nul set /p, which is much faster. Piping generates two new cmd processes, because each side of the pipe is run in a separate process, which costs time.