0

I have the following function that works like this: You input a string that resembles: text text=text like this: call :afterchar text text=text and it outputs with text=text on a line without creating a new one. While it is currently working well, it also outputs "The Syntax of this command is incorrect" when I run it the first time. I don't understand what is triggering this error.

@echo off
:read
shift
if "%1"=="" set err=2 & goto help
if "%2"=="where" goto where
set DB=%1.db
if not exist "C:\users\Public\Temp\%DB%"  call :c 0c "Database not found: %2" & exit /b 1
setlocal EnableDelayedExpansion
set numline=0
for /f "tokens=1,2,3,4,5,6,7,8,9,10* delims=# skip=1" %%A in (C:\users\Public\Temp\%DB%) do (
    set /a numline+=1
    if not "%%A"=="" call :afterchar %%A
    if not "%%B"=="" call :afterchar %%B
    if not "%%C"=="" call :afterchar %%C
    if not "%%D"=="" call :afterchar %%D
    if not "%%E"=="" call :afterchar %%E
    if not "%%F"=="" call :afterchar %%F
    if not "%%G"=="" call :afterchar %%G
    if not "%%H"=="" call :afterchar %%H
    if not "%%I"=="" call :afterchar %%I
    if not "%%J"=="" call :afterchar %%J
    echo.
)
goto skpp

:afterchar
echo|set /p="  %2=%3  "
exit /b




:skpp
if %errorlevel%==0 call :C 0a "Success."
exit /b
3
  • You asking a question regarding For Loop Delims to extract text and posted just a subroutine that isn't related to For-Loop. Here a lot of telepathic people, but I think even they wouldn't be able to help you with catch-22 information you provided
    – Alex
    Jul 28, 2018 at 13:25
  • sorry I forgot to change it :D
    – Mark Deven
    Jul 28, 2018 at 14:23
  • Well <nul set /p "dummy=blah" is usually used to output something without newline. Check if there is nothing to output with Ìf "%2%3" equ "" exit
    – LotPings
    Jul 28, 2018 at 16:08

1 Answer 1

1

When you execute the code exactly as given in your example,
code flow runs through into the subroutine because there is no goto :eof or Exit /b in front of the label :afterchar to prevent this.

As there are no arguments passed to the main batch this time the try to execute:

echo | set /p="  =  "

causes the error. You would see this if you execute the batch with set echo on

:: Q:\Test\2018\07\28\SU_1344049.cmd

call :afterchar text text=text

:: here belongs a termination
goto :eof

:afterchar
echo|set /p="  %2=%3  "
exit /b
4
  • I dont see how, added my whole code to the edit
    – Mark Deven
    Jul 28, 2018 at 15:48
  • In batch there is no implicit separation of a subroutine, you have to do this yourself, I'll insert it in the above code now.
    – LotPings
    Jul 28, 2018 at 15:51
  • 1
    Did refresh my browser to late to see update, that's quite different but the same problem you call the sub with only one argument and the command echo|set /p=" %2=%3 " evaluates to echo|set /p=" = " being illegal syntax.
    – LotPings
    Jul 28, 2018 at 15:55
  • I see. It is because the last line ends with a hashtag. Is there any way I could handle that and predict it? EDIT NEver mind I see a simple way. Thank for your help
    – Mark Deven
    Jul 28, 2018 at 16:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .