Cmd save "to file without new line

Is it possible to save the special character "into a string without a new line? I tried the codes below, but none of them work:

echo|set /p=""" >>C:\text.txt echo|set /p=" >>C:\text.txt echo|set /p=^" >>C:\text.txt set /p=""" <nul >> C:\text.txt set /p=" <nul >> C:\text.txt set /p=^" <nul >> C:\text.txt 
+5
source share
3 answers

You almost had it

 <nul >"file.txt" set/p=""" 

but, as Squashman points out, if you try to write to the root of your disk, you will need an elevated prompt

+5
source

Here is a slightly different method that does not require redirection before the set /P command:

 set /P =""^" < nul >> "C:\text.txt" 

Since the last of the three quotes is escaped as ^" , the rest of the command line is not displayed, and therefore the redirection operators < and >> recognized.

+4
source

On the command line, not one-line, but as a batch file, the following works for me:

 >>output.txt ( echo|set/p=""" ) 

Or, if you want to press return to write it, use the following, very similar:

 >>output.txt ( set /p=""" < nul ) 

You can also set it as a function for dynamic use:

 >>"%~dp1" ( echo|set/p=""" ) 

To use this, you pass the file name as the first command line argument as follows:

addQuoteTo.bat "C: \ my Path \ toFile \ file.txt"

It was interesting to play with :)

+2
source

Source: https://habr.com/ru/post/1263602/


All Articles