I'm trying to load and save variables into a file.
For example:
@echo off
set /a number=1
echo %number%>text.txt
How do I store the number from the text file in a variable for example variable1?
As mentioned by aschipfl, there are two ways to do it:
set /P (redirect variable to a text file and read (the file) with set /p).for /F loop.As the first way is already mentioned by Tiw, I will only deal with the second one. You should do:
@echo off
set "number=1"
(echo %number%)>text.txt
for /F "delims= eol=" %%A IN (text.txt) do set "variable1=%%A"
Note that:
/a option in set is used only to perform arithmetic operations. It doesn't mean that the interpreter will 'see' this as a number.echoing an extra space in the txt file. echo %number%>txt won't work if %number% is <10 because 0 is STDIN, 1 is STDOUT, 2 is STDERR and numbers from 3 to 9 are undefined. Apparently, it's sending STDIN/STDOUT/STDERR/UNDEFINED of nothing to a file.Further reading:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With