Hi Friends,
I have Script below in one .bat file and am calling other .bat file which contained the function
but it is not working.
-------Bat1.bat
@echo off
setlocal enableExtensions disableDelayedExpansion
set file=D:\Rajnish_GTT\R1Test.txt
for /f "tokens=1 delims=, " %%a in (%file% ) do (
setlocal enabledelayedexpansion
SET "string1=%%a" & CALL D:\Rajnish_GTT\islength.bat result1 !string1! -----> Calling other .bat file with parameter.
if "!result1!" GTR "6" (
echo(field "%%~a" Not a 6 Digit Long)
)
)
---------------Bat2.bat
@echo off
setlocal enableExtensions disableDelayedExpansion
(
SET S="S=!%~2!#"
SET "LEN=0"
FOR %%P IN (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) DO (
IF "!S:~%%P,1!" NEQ "" (
SET "S=!S:~%%P!"
)
)
)
(
ENDLOCAL
SET "%~1=%LEN%"
EXIT /B
)
Example data as below.
id
001 --- return 4 digit.
A002 --- return 6 digit.
Second .bat file checking the length of fields.
Kindly help.
.Bat File calling with other .bat file with paramater isue
Moderator: DosItHelp
-
- Posts: 21
- Joined: 16 Aug 2019 23:35
Re: .Bat File calling with other .bat file with paramater isue
I see you copied in the string length function wrong. Review your other thread and try again. You're missing an entire parameter.
Re: .Bat File calling with other .bat file with paramater isue
Hi ,
your strlen batch is wrong, you doubled S="S=
The next problem is, that your parameters are wrong when calling the batch.
The !string1! results into the expansion to the content, but the batch file expects only a variable name, not the content itself.
You have to call it
There is a good reason for the use of variable names instead of the content.
It's impossible to use CALL with an arbitrary content. The CALL command modifies the content.
Btw. I build a quite better version of the strLen function, this version can handle strings up to the maximum possible length of 8191 characters
your strlen batch is wrong, you doubled S="S=
Code: Select all
SET S="S=!%~2!#"
Code: Select all
CALL ...\islength.bat result1 !string1!
You have to call it
Code: Select all
CALL ...\islength.bat result1 string1
It's impossible to use CALL with an arbitrary content. The CALL command modifies the content.
Btw. I build a quite better version of the strLen function, this version can handle strings up to the maximum possible length of 8191 characters
Code: Select all
(
setlocal EnableDelayedExpansion
(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
)