Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
goodywp
- Posts: 265
- Joined: 31 Jul 2017 09:57
#1
Post
by goodywp » 22 Oct 2024 07:38
Hi all,
This code below I was using before. But today I used it again just found that it echo double times, I need know why that happened...
The Sample.txt just list as NAXAUTO-1 NAXAUTO-2 NAXAUTO-3 NAXAUTO-4 NAXAUTO-5 NAXAUTO-6 NAXAUTO-7 NAXAUTO-8 NAXAUTO-9 NAXAUTO-10 NAXAUTO-11 NAXAUTO-12
I used this code to test each values in this Sample.txt has been echo properply but it echo twice the second round just
ECHO is off
Code: Select all
@echo off
set TC_ID=Sample
for /f "tokens=1-12 delims=," %%A in (C:\CATA_AUTO\ata-master\BVT\BVTTAG\FAPS\%TC_ID%.txt) do call :ManualRepl %%A %%B %%C %%D %%E %%F %%G %%H %%I %%J %%K %%L
:ManualRepl
set "var1=%~1"
set "var2=%~2"
set "var3=%~3"
set "var4=%~4"
set "var5=%~5"
set "var6=%~6"
set "var7=%~7"
set "var8=%~8"
set "var9=%~9"
shift
set "var10=%~9"
shift
set "var11=%~9"
shift
set "var12=%~9"
echo %var1%
echo %var2%
echo %var3%
echo %var4%
echo %var5%
echo %var6%
echo %var7%
echo %var8%
echo %var9%
echo %var10%
echo %var11%
echo %var12%
The output as below:
NAXAUTO-1
NAXAUTO-2
NAXAUTO-3
NAXAUTO-4
NAXAUTO-5
NAXAUTO-6
NAXAUTO-7
NAXAUTO-8
NAXAUTO-9
NAXAUTO-10
NAXAUTO-11
NAXAUTO-12
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
Why it echo twice and I need clean output
Thanks
-
Lucky4Me
- Posts: 24
- Joined: 21 Oct 2020 06:33
#2
Post
by Lucky4Me » 22 Oct 2024 08:47
put an exit /b or goto :eof between the for /f and :ManualRepl
Code: Select all
for /f "tokens=1-12 delims=," %%A in (C:\CATA_AUTO\ata-master\BVT\BVTTAG\FAPS\%TC_ID%.txt) do call :ManualRepl %%A %%B %%C %%D %%E %%F %%G %%H %%I %%J %%K %%L
exit /b
:ManualRepl
Code: Select all
for /f "tokens=1-12 delims=," %%A in (C:\CATA_AUTO\ata-master\BVT\BVTTAG\FAPS\%TC_ID%.txt) do call :ManualRepl %%A %%B %%C %%D %%E %%F %%G %%H %%I %%J %%K %%L
goto :eof
:ManualRepl
-
goodywp
- Posts: 265
- Joined: 31 Jul 2017 09:57
#3
Post
by goodywp » 22 Oct 2024 11:16
Oh Ya Thanks for picking up the mistake...
-
miskox
- Posts: 632
- Joined: 28 Jun 2010 03:46
#4
Post
by miskox » 23 Oct 2024 05:51
Maybe you would like to know the explanation:
Just run this:
Code: Select all
@echo off
echo BEFORE
for /L %%f in (1,1,3) do call :DOIT %%f
echo AFTER
goto :EOF
:DOIT
echo %1
goto :EOF
Output:
As you can see FOR command calls : DOIT three times and then execution continues after this FOR command. After the ECHO AFTER there is a GOTO :EOF command which exits the .cmd (or you could send the execution flow to somewhere else) and because of this it never reaches the : DOIT subprogram again - your code did that: after FOR completion it continued with the :ManualRepl subprogram.
Saso
-
goodywp
- Posts: 265
- Joined: 31 Jul 2017 09:57
#5
Post
by goodywp » 24 Oct 2024 12:02
Great! it really help to understand the steps!
Thank Saso!!!!