Windows 7 batch files: How to write string to text file without carriage return AND trailing space?
22,697
This command should work exactly like you want - write only "hello", without any extra symbols.
> echo|set /P ="hello" > foo
> dir foo
...
09.07.2012 19:25 5 foo
1 File(s) 5 bytes
Looks like exactly 5 symbols without CR+LF to me.
Author by
oscilatingcretin
Updated on September 18, 2022Comments
-
oscilatingcretin over 1 year
I am trying to have my batch file write a string of text to a text file. At first, the command I was using was writing an extra carriage return to the end of the string, but I found this command that prevented that:
echo|set /p=hello>hello.txt
However, now it's putting a trailing space at the end. I need only the string I specify to be written without any extra characters. Is this possible?
-
Sean C. almost 12 yearsOleg is right. The SET /P is designed to output a question and accept input from the user on the same line, so it automatically excludes line breaks. The
wc
command actually counts LF characters, so it should show 0 if the line feed is actually omitted. In Oleg's example that is true. -
oscilatingcretin almost 12 yearsvery good! Worked awesomely!
-
will over 8 yearsI'm not sure why that should work, however I found it doesn't work for spaces. Anyone got an idea how I can pad on the left?