The following Windows batch file sets the contents of the out.txt
file to two ASCII characters, namely: X
and <LF>
(0x58 and 0x0A ).
@echo off
SETLOCAL
SET LF=^
set /p=X^%LF%%LF%<nul>out.txt
Note the mandatory empty lines after the statement SET LF=^
How to change this batch file so it sets the contents of the out.txt
file to only one ASCII character, namely the: 0x0A (<LF>
) character?
RESTRICTIONS:
This question relates only to the internal commands implemented in cmd.exe
(not PowerShell !) and only to the native external commands installed in standard Windows installations >= Windows 7 x64 (no 3rd party tools, no debug.exe
). This question is not about how to accomplish this goal with scripting languages such as VBscript or JSscript nor how to write a program in C, C#, Python or any language other than the Windows batch language (if you can call it that). Assume a restricted user without administrative rights, so neither fsutil
nor certutil
work.
A single line feed can be written to a file by the use of the prompt
command
@echo off
setlocal
(set prompt=^
%= Don't delete this line =%
)
cmd /d /k < nul > single-linefeed.txt