Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing Numbers to a text file - batch file

This should be a simple one and I am dissapointed with myself but cant for the life of me find a solution! I am trying to write the number 1 to a text file in a BAT script. If I do the below it works but leaves a trailing space after the number which I cannot have. I know you can remove the trailing space by deleting the space between the 1 and the > (this works with letters) but with numbers all of a sudden I get a message saying - ECHO is OFF.

ECHO 1 > mytextfile.txt
*This works but leaves a trailing space*

ECHO 1> mytextfile.txt
*This gives me an error saying ECHO is OFF*
like image 503
Ben Collins Avatar asked Jun 27 '12 11:06

Ben Collins


2 Answers

The problem is that echo 1> myTextFile.txt will not echo 1, instead the echo command is empty and the redirection goes to stream 1.

You could simply move the redirection to the front.

>mytextfile.txt echo 1
like image 162
jeb Avatar answered Sep 27 '22 02:09

jeb


1> is a special command. Use (ECHO 1) > mytextfile.txt instead.

like image 27
embedded.kyle Avatar answered Sep 25 '22 02:09

embedded.kyle