I run a batch file to process some code, it calls another batch file at the same time and should get a returned variable, but the methods described in the local / endlocal man pages do not seem to work here, what am I doing wrong?
first batch file:
@ECHO OFF
setlocal
call secondbatchfile.bat xyz
echo. [%val1%]
second batch file:
@if (@a==@b) @end /* <== btw what does this code do ???
@echo off
setlocal enabledelayedexpansion
set "URL=%~1"
set bla bla ...
do bla bla ...
for /f "delims=" %%I in ('cscript /nologo /e:jscript "%~f0" "%URL%"') do (
rem trim whitespace from beginning and end of line
for /f "tokens=*" %%x in ("%%~I") do set "line=%%x"
rem test that trimmed line matches "variable=number"
echo !line! | findstr /i "^to[a-z]*=[0-9]*" >NUL && (
rem test was successful. Scrape number.
for /f "tokens=2 delims==" %%x in ("%%I") do set "val1=%%x"
echo !val1! <== this works
ENDLOCAL & SET top=%val1% <== this not
)
)
it leads to:
c:\test>firstbatchfile.bat
123456789 <== this works
[] <== this not
I tried using a different return var syntax like !val1!or %%val1- no one worked. What am I missing?
UPDATE:
regarding another example here on the site , I tried:
call seconbatchfile.bat xyz ret1
echo. [%2%] [%ret1%]
and in the secon file:
rem ENDLOCAL & SET %2=!val1!
doesn't work too?
DECISION:
script rojo, , , :
for /f "delims=" %%I in ('cscript /nologo /e:jscript "%~f0" "%URL%"') do (
rem trim whitespace from beginning and end of line
for /f "tokens=*" %%x in ("%%~I") do set "line=%%x"
rem test that trimmed line matches "variable=number"
echo !line! | findstr /i "^[a-z]*=[0-9]*" >NUL && (
echo(%%I
)
)
, , , :
@ECHO OFF
setlocal
for /f "delims=" %%I in ('secondbatchfile.bat "http://xyz"') do (
echo %%I | findstr /i "top" >NUL && (
for /f "tokens=2 delims==" %%x in ("%%I") do (
set "updir=%%x"
)
)
echo %%I | findstr /i "low" >NUL && (
for /f "tokens=2 delims==" %%x in ("%%I") do (
set "lowdir=%%x"
)
)
)
echo.[%updir%]
echo.[%lowdir%]
rojo