1
@echo off
:start
SET /A number=%RANDOM% * 3 / 32768 + 1
echo %number%>number.txt
PING localhost -n 2 >NUL
goto start

It should generate a random number from 1-3. And it does. But the .txt file is just empty and in the console, I get the message: "Echo is turned off".

Can someone help me?

Kevin Mueller
  • 628
  • 3
  • 10
  • 23
  • seems to work in my PC. And unrelated but [`timeout`](https://stackoverflow.com/q/1672338/995714) might be better than ping – phuclv Sep 13 '17 at 07:23

1 Answers1

2
>number.txt echo %number%

A digit directly before a redirector redirects a logical device (0=stdin, 1=stdout, 2=stderr, others unassigned). The position of the redirection instruction is generally irrelevant; only at the end of the command by convention and historical usage.

Magoo
  • 77,302
  • 8
  • 62
  • 84
  • no need to reverse the order, a space before `>` will help `echo %number% >number.txt` – phuclv Sep 13 '17 at 10:01
  • @LưuVĩnhPhúc: Not so. The space will be output to the file, but reversing the order will prevent the file having terminal spaces on the line. – Magoo Sep 13 '17 at 10:23