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?
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?
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.
This should give you the desired result for adding single, double-quote "
:
echo| set /p=^""^">>abc.txt
Where this will give a result of double, double-quote ""
echo| set /p=^"""^">>abc.txt
To break it down, we escape the opening and closing quotations ^"
with the desired result inbetween, these examples shows the desired results in parenthesis, with the escaped "
outside of the parenthesis ^"(")^"
or ^"("")^"
In short, no matter how many double quotes you want inbetween, as long as the opening and closing double-quotes are escaped.
So using the parenthesized examples as above, if you actually do:
echo echo| set /p=^"(")^"
it will only return the result of (")
Note the parsing is different when using echo|
compared to @stephan's solution using <nul
as pipe will initiate a second process and <nul
does not.