windows - Replacing a specific line in batch and reading and setting what i read as a variable -
i wanted create menu this:
mode 59, 300 set line=========================================================== echo %line% echo tool colour menu! echo %line% echo. echo take background colour! echo. echo 1 = bluish echo 2 = greenish echo 3 = aqua echo 4 = reddish echo 5 = violet echo 6 = yellowish echo 7 = white echo 8 = grayness echo 9 = lite bluish echo 10 = lite greenish echo 11 = lite aqua echo 12 = lite reddish echo 13 = lite violet echo 14 = lite yellowish echo 15 = bright white echo. set /p background_app=enter number of colour want background (or come in default):
so menu background_app variable!
and then:
mode 59, 300 set line=========================================================== echo %line% echo tool color menu! echo %line% echo. echo take text color! echo. echo 1 = bluish echo 2 = greenish echo 3 = aqua echo 4 = reddish echo 5 = violet echo 6 = yellowish echo 7 = white echo 8 = grayness echo 9 = lite bluish echo 10 = lite greenish echo 11 = lite aqua echo 12 = lite reddish echo 13 = lite violet echo 14 = lite yellowish echo 15 = bright white echo. set /p text_app=enter number of color want text (or come in default):
this variable %text_app%
after user input wanted save variables in txt file retrieve values later in case user runs tool (to maintain colours person choosing)
but have tried:
:savevars ( echo backuground=%background_app% echo text=%text_app% ) >colors.txt goto :eof
for illustration save this:
background=1 text=7
and comes dilemma, because wanted read value colors.txt , set variables as:
%background_apptxt% %text_apptxt%
how can read value of background , text? help :)
well it's pretty easy understand example:
colors.txt contains lines:
background=1 text=2
so illustration used batch create test batch:
@echo off set background_app=black set text_app=green :savevars ( echo background=%background_app% echo text=%text_app% ) >colors.txt /f "tokens=1,2 delims==" %%a in (colors.txt) set "%%a_app=%%b"
how echo %background_app% , echo 1 time again %text_app% ? give thanks you
use /f loop read , parse each line. can set token delimiter =
2 tokens.
for /f "tokens=1,2 delims==" %%a in (colors.txt) set "%%a_app=%%b"
the code easier if text file contains total name of each variable. use
for /f "delims=" %%a in (colors.txt) set "%%a"
windows command-line batch-file dos
No comments:
Post a Comment