1.

Solve : SET will not work, variable keeps its old value?

Answer»

The script will be executed via command prompt on XP.

The problem is the variable ORIG_FILENAME keeps its old value and won't be updated. The value should come out of a file which with be READ using the FOR command.

This is the code:

Code: [Select]
echo START FINDSTR

  findstr /m "%%b" C:\Temp\gasdats\*.* > tmp_filename.txt && (

    echo "%%ORIGFILE_NAME%% (for)" %ORIG_FILENAME%

    for /f "tokens=4-13 delims=\_" %%k in (tmp_filename.txt) do SET ORIG_FILENAME=%%k_%%l_%%m_%%n_%%o__%%p_%%q_%%r_%%s

    echo "%%ORIGFILE_NAME%% (after)" %ORIG_FILENAME%
   

    echo ^<td^>%ORIG_FILENAME%^</td^> >> report_gasdats_%UNIQUE%.html
    echo ^<td^> >> report_gasdats_%UNIQUE%.html

    echo "DO SQLQUERY WITH %%ORIG_FILENAME%%" %ORIG_FILENAME%


    sqlplus -s /nolog query2.sql %ORIG_FILENAME% >> report_gasdats_%UNIQUE%.html

    echo ^</td^> >> report_gasdats_%UNIQUE%.html

  ) || (


    echo ^<td^>NEE^</td^>^<td^>-^</td^> >> report_gasdats_%UNIQUE%.html
    echo ^<td^>-^</td^>
  )

  echo EIND FINDSTR



And in the logging where we can see the variable ORIG_FILENAME keeps its old value CATS_RECVD_2008_07_29__14_43_01_667.dat .cmpr.DA. The logging says the SET command has updated ORIG_FILENAME to CATS_RECVD_2008_07_29__15_02_26_621.dat .


Code: [Select]
START FINDSTR
"%ORIGFILE_NAME% (for)" CATS_RECVD_2008_07_29__14_43_01_667.dat.cmpr.DA

C:\Temp>set ORIG_FILENAME=CATS_RECVD_2008_07_29__15_02_26_621.dat
"%ORIGFILE_NAME% (after)" CATS_RECVD_2008_07_29__14_43_01_667.dat.cmpr.DA
"DO SQLQUERY WITH %ORIG_FILENAME%" CATS_RECVD_2008_07_29__14_43_01_667.dat.cmpr.DA
EIND FINDSTR


Can somebody help me with this?1.

setlocal enabledelayedexpansion

2.
VARIABLES which are SET inside (
parenthetical expressions
)

need to be shown with ! instead of % symbols

3. Google for delayed expansion


Thnx! That's it!

I was using systemvars instead of local ones.



Discussion

No Comment Found