- 1 year ago
Echo a number to a text file in batch
To echo a number to a text file in a batch script, you can use the echo
command followed by the number and then redirect the output to a text file using the >
operator. Here's an example:
batch@echo off
set number=42
echo %number% > output.txt
echo Number %number% echoed to output.txt
In this example, the number 42 is stored in the %number%
variable. The echo %number%
command is used to display the value of the variable. The >
operator is then used to redirect the output to the output.txt
file. If the output.txt
file doesn't exist, it will be created. If it already exists, its contents will be overwritten.
After running the script, the number 42 will be echoed to the output.txt
file. You can modify the value of the number
variable to echo a different number to the file.
Note: If you want to append the number to an existing file instead of overwriting it, you can use the >>
operator instead of >
:
batchecho %number% >> output.txt
This will append the number to the end of the file without removing the existing content.