0

This is my current code:

cls
@echo OFF
echo 1>>test.txt

I know this is should be simpler but I cannot figure out how to print just the number 1 to the text file. I know putting quotes around the number 1 will make "1" print to test.txt, but I need it to just be the number one. Thanks in advance for the help.

3
  • Ah thanks worked perfectly! Commented Jan 15, 2016 at 16:50
  • (echo 1)>>test.txt Commented Jan 15, 2016 at 17:02
  • Please post as answers guys. Commented Jan 15, 2016 at 18:57

1 Answer 1

1

1> is a special way of redirecting standard input and output.

If you had echoing on you would see cmd adding a 1 in front of your redirection, as you put a number there it doesn't bother.

The answer is to leave a space before the redirection character.

echo 1 >>test.txt

and leave ECHO ON and you'll see cmd change it to

echo 1 1>>test.txt

From The Windows NT Shell Scripting by Tim Hill

Table 2.4 Command Redirection Symbols

Symbol Description

>file Redirects command output to the file specified. You can also use a standard device name such as LPT1, CON, PRN or CONOUT$ as the file name. Any preexisting contents of the file are lost.

>>file Redirects command output to the file specified. If the file already exists, all command output is appended to the end of the file.

2>file Redirects command error output to the file specified. You can also use a standard device name such as LPT1, CON, PRN or CONOUT$ as the file name. Any preexisting contents of the file are lost.

2>&1 Redirects command error output to the same location as command output. This makes any command output redirection also apply to command error output.

cmd1 | cmd2 Pipes the command output of cmd1 to the command input of cmd2. Multiple pipe characters are allowed, creating a chain of commands, each sending output to the next command in the chain.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.