jeudi 30 mars 2017

Send a random number output every x seconds in to COM1 in Batch

I'm trying to send a random number to my program that listens to a virtual COM port for testing reasons. I though a quick .batch would do it since I'm too lazy to do

echo 54646 > COM1

Every time.

What I developed (using stackoverflow example) is:

:loop
%RANDOM%
echo %RANDOM% > COM1
sleep 1
goto loop

However, it doesn't run as wanted and outputs:

C:\Users\user\Desktop>goto loop

C:\Users\user\Desktop>13599
'13599' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\user\Desktop>echo 20524  1>COM1

C:\Users\user\Desktop>sleep 10
'sleep' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\user\Desktop>goto loop

C:\Users\user\Desktop>11259
'11259' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\user\Desktop>echo 2973  1>COM1
^CTerminate batch job (Y/N)?

Questions:

  • What's wrong with my code?

  • Why is the script running the command as echo 20524 1>COM1? Where does the '1'> come from?




Aucun commentaire:

Enregistrer un commentaire