batch file - how to make variables preserved after endlocal command -


this question has answer here:

thanks nate. works.
need output variable script use later.
there 2 outputs need. first count variable integer output, second string variable equal last string character in "word".
so, need 2 variable see in last row of finished script before "press key continue...".
1 last integer variable , 1 last string variable.

i need these 2 variables later scripting in script.
how can have it? here script works yesterday.

@echo off :input set /p word=input word: if not defined word goto input (echo %word%)> tempfile.txt %%x in (tempfile.txt) ( set /a lenght=%%~zx - 2 )  del tempfile.txt echo %word% got %lenght% characters setlocal enabledelayedexpansion  /l %%m in (1,1,!lenght!) (   set /a count=%%m   set /a index=%%m-1   call echo !count! %%word:~!index!,1%% )   (call echo %%word:~!index!,1%%)>tf.txt   /f "tokens=*" %%a in (tf.txt) ( set line=%%a set char=!line:~0,1!  )  pause  echo %count% %char%  endlocal  pause 

try technic tear down wall of setlocal enabledelayedexpansion / endlocal:

@echo off&setlocal set "word=abcdefghij" set /a lenght=10  /l %%m in (1,1,%lenght%) (     set /a $count=%%m     set /a index=%%m-1     setlocal enabledelayedexpansion     call echo !$count! %%word:~!index!,1%%     call set "$laststring=%%word:~!index!,1%%"     /f %%i in ('set $') (if "!"=="" endlocal)& set "%%i" ) echo(  echo !$count! !$laststring! echo %$count% %$laststring% 

(source)


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -