how to access argument passed in a function
Posted: 08 Nov 2021 19:51
Dear all,
based on
https://stackoverflow.com/questions/583 ... batch-file
below is my code to find out string length of a variable called
output is as follow;
unfortunately argument should not be C:\:\PROGRA~1\avs\bin it should be 149055640992_scn_lap63-sin_wcdb_20211109_094802_set_until_scn_no_newname_datafile_no_newname_tempfile_no_rename_redo_restore_db_preview_validate
so how do I access the argument passed in a function? It seems that no matter how I setlocal, arguments seems to equate the the glocal value.
many thanks in advance!
based on
https://stackoverflow.com/questions/583 ... batch-file
below is my code to find out string length of a variable called
Code: Select all
SET trace_log_script_name_prefix=%until_number%_%scn_or_sequence%_%source_host_db%_%log_datetime%_%rman_script_prefix%
call :strlen result trace_log_script_name_prefix
REM ********* function *****************************
:strlen <resultVar> <stringVar>
(
setlocal EnableDelayedExpansion
echo argument %~2
exit /b
(set^ tmp=!%~2!)
if defined tmp (
set "len=1"
for %%P in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do (
if "!tmp:~%%P,1!" NEQ "" (
set /a "len+=%%P"
set "tmp=!tmp:~%%P!"
)
)
) ELSE (
set len=0
)
)
(
endlocal
set "%~1=%len%"
exit /b
)
Code: Select all
setlocal EnableDelayedExpansion
echo argument C:\PROGRA~1\avs\bin
exit /b
(set tmp=!C:\PROGRA~1\avs\bin! )
if defined tmp (
set "len=1"
for %P in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do (if "!tmp:~%P,1!" NEQ "" (
set /a "len+=%P"
set "tmp=!tmp:~%P!"
) )
) ELSE (set len=0 )
)
argument C:\PROGRA~1\avs\bin
so how do I access the argument passed in a function? It seems that no matter how I setlocal, arguments seems to equate the the glocal value.
many thanks in advance!