Page 1 of 1

getting for command to work

Posted: 27 Feb 2015 12:46
by gbattis
need help on the last lines of this script with for command i need it to set %thepasswordtouse% variable to the text in the document. This doc contains only 1 line of txt.

Code: Select all

@echo off

IF EXIST sam2.pas goto :passwordfiledoesexist (
   
   ) else (
   
   cls
   echo Welcome to Greg's Batch OS
   set /p passwordin=Pick a password to log in with:
   doskey /reinstall
   set /p passwordcheck=Retype the password:
   doskey /reinstall
   
   if "%passwordin%" == "%passwordcheck%" (
   goto :passwordisgud
      ) ELSE (
      :: test only part
      cls
      echo Passwords do not match.
      pause
      goto :passwordredo
      :: eot
      )
   :passwordisgud   
   echo passwords match.
   pause
   cls
   goto :
   )

:passwordfiledoesexist
cls
doskey /reinstall
for /f %%a in ('findstr hextemp.pas') do set thepasswordtouse=%%a
echo %%a
pause

Re: getting for command to work

Posted: 27 Feb 2015 13:04
by ShadowThief
If hextemp.pas only has one line, you can just use set /p

Code: Select all

set /p thepasswordtouse=<hextemp.pas

Re: getting for command to work

Posted: 27 Feb 2015 13:06
by Squashman
ShadowThief's solution is the most concise.

But your FOR /F command should have looked like this if you wanted to use it.

Code: Select all

for /f "delims=" %%a in (hextemp.pas) do set thepasswordtouse=%%a

Re: getting for command to work

Posted: 27 Feb 2015 13:19
by gbattis
thank you to both of you for the solution. :)