Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
    
Doesn't echo mystring>test.txt do just that? –  Sean C. Jul 9 '12 at 15:14
    
That's how I was doing it before when it was adding a carriage return at the end. –  oscilatingcretin Jul 9 '12 at 15:16
    
Odd; I just tested it myself. When I open it in vim, the output contains no line breaks or spaces after the string. –  Sean C. Jul 9 '12 at 15:17
    
I just tested it in a command window and the carriage return is there when I open it in Notepad. –  oscilatingcretin Jul 9 '12 at 15:18
    
I am 100% wrong on this. Sorry. –  Sean C. Jul 9 '12 at 15:37

1 Answer 1

up vote 5 down vote accepted

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.

share|improve this answer
    
Oleg 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. –  Sean C. Jul 9 '12 at 15:35
    
very good! Worked awesomely! –  oscilatingcretin Jul 9 '12 at 15:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.