You get the ECHO is off/on
message if you just run echo
with no operands. That means, for some reason, your kurczaki
variable is not being set to anything. Hence you should echo each variable after you set it to see where the problem lies:
SET /a _rand=(%RANDOM%*5/32768)+1
echo .%_rand%.
Set /a zmienna=%zmienna%-%_rand%
echo .%zmienna%.
set kurczaki=%zmienna%
echo .%kurczaki%.
echo %kurczaki%> bin\DB\smth.txt
When I do this from the command line, there's a difference when the >
redirection is hard up against what you're outputting, when that thing can be used as a file handle:
C:\Pax> set xx=7
C:\Pax> echo %xx%>zz.txt
ECHO is on.
C:\Pax> type zz.txt
<no output>
C:\Pax> echo %xx% >zz.txt
C:\Pax> type zz.txt
7<space>
So I think your solution is just to not do that. What is happening in this case is that the echo %xx%>zz.txt
is being converted exactly into:
echo 7>zz.txt
which is not sending the 7
to the file. Instead, it is attaching file handle 7
to that file and then, because your echo
is only writing to file handle 1
(standard output), nothing appears in the file.
In addition, because the %xx%
has been absorbed for the redirection, there are no longer any arguments to echo and you therefore get the ECHO is off
message. Further proof can be found with:
C:\Pax> set xx=1 7
C:\Pax> echo %xx%
1 7
C:\Pax> echo %xx%>zz.txt
1
with the 7
being absorbed for the redirection, leaving only the 1
.
But beware that spaces often find their way into output if you don't do it in a certain way. To that end, I would change the line to be:
echo>bin\DB\smth.txt %kurczaki%
This should both ensure no spaces surrounding the variable in the output file, and also the actual writing of the value to said file.