getting for command to work

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
gbattis
Posts: 12
Joined: 12 Jan 2015 11:35
Contact:

getting for command to work

#1 Post by gbattis » 27 Feb 2015 12:46

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

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: getting for command to work

#2 Post by ShadowThief » 27 Feb 2015 13:04

If hextemp.pas only has one line, you can just use set /p

Code: Select all

set /p thepasswordtouse=<hextemp.pas

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: getting for command to work

#3 Post by Squashman » 27 Feb 2015 13:06

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

gbattis
Posts: 12
Joined: 12 Jan 2015 11:35
Contact:

Re: getting for command to work

#4 Post by gbattis » 27 Feb 2015 13:19

thank you to both of you for the solution. :)

Post Reply