mercredi 21 octobre 2015

Echo Outputs When Writing to File {BATCH}

When I use this code to select a character from my list, it works just fine but when I write it to a file using:

echo %pwd%>>pwd.gen

It will some times put the word "ECHO" randomly in the middle of the strings generated. Here is an example:

jUrkunjcxC

ecRECHOsI5w0T

DmJfat13fT

UWXOysW7Gb

pPmS7138Ve

nFkh32ECHOJd1

You can see it appears in line 2 and 6. This only happens about 20% of the time.

Here is the code:

@echo off
title Password Generator
color f0
:firstRun
set /a cnt=0
cls
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
set /p Len=What length should the password be?
set /a Len=%Len%-1
cls
set /p Amt=How many would you like to generate?
cls
goto start

:start
set alfanum=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
set pwd=
FOR /L %%b IN (0, 1, %Len%) DO (
SET /A rnd_num=!RANDOM! * 62 / 32768 + 1
for /F %%c in ('echo %%alfanum:~!rnd_num!^,1%%') do set pwd=!pwd!%%c
)

echo %pwd%>> pwd.gen

set /a cnt=%cnt%+1
if %cnt%==%Amt% goto end
goto start

:end
cls
echo Done!
echo Results have been saved to "pwd.gen"
echo.
choice /c YN /m "Restart?"
if %errorlevel%==1 goto firstRun




Aucun commentaire:

Enregistrer un commentaire