A common batch file to setup variables -
i working on multiple batch files , want them share variables, created batch file has these setups setupenv:
rem general setup :: pause or not after running batch file set ispause = true :: directory source code located set directory = d :: folders primary & secondary source code located :: have 2 source code folders, if don't have them pointing same folder set primary_source_code = \dev\app set secondary_source_code = \dev\app2 :::::::::::::::::::::::::::::::::::::::::::: xampp ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: rem if you're using xampp set these :: destination folder set base_destination = c:\xampp\htdocs :: base url pointing destination folder (in cases it's localhost) set base_url = http://10.0.2.65 :::::::::::::::::::::::::::::::::::::::::: angular ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: rem if you're using angular set these :: folder built code copied set build_file = dist and batch file i'm calling file first:
::setup call ../setupenv echo %directory% dir pause; the problem though file runs smoothly , can see in outputs things being setup, variables not coming across file i'm calling from. in example %directory% not being printed.
edit tried using joey's answer:
::setup /f "delims=" %%x in (../setupenv.txt) (set "%%x") echo %directory% dir pause but didn't work either , %directory% didn't printed
setting variables in called batchfile works, long don't use setlocal in called batchfile (there implicite endlocal, when returns, variables lost):
> type a.bat set var=old echo %var% call b.bat echo %var% > type b.bat set var=new > a.bat > set var=old > echo old old > call b.bat > set var=new > echo new new > for alternative for solution, change to:
for /f "delims=" %%a in ('type b.bat^|findstr /bic:"set "') %%a this "execute" lines, start set (ignoring capitalization), can keep comments inside file.
note: ... set "%%a" adds set line (you have 1 in file), resulting in set "set var=value", don't want.
Comments
Post a Comment