Search code examples
batch-filedos

How to use CALL function in DOS 6.22?


I have written a batch file that runs fine under Windows Command Prompt, but I would like to be able to run it after POST in DOS. I have copied my code to AUTOEXEC.BAT file which gets executed automatically; however it comes up with syntax errors once it reaches the call command and the rest.

echo. This script is counting the # of POSTs.
echo. The POST # value is saved in TEST.txt.
echo.

call:myPOSTTest

for /f "tokens=* delims=" %%x in (A:\TEST.txt)  do echo POST# %%x

echo. &pause&goto:eof
::--------------------------------------------------------
::-- Function section starts below here
::--------------------------------------------------------

:myPOSTTest    - here starts my function identified by its label 

set var=0

if EXIST A:\TEST.txt (
     for /f %%x in (A:\TEST.txt) do (set /a var=%%x+1)
)

echo %var% >> A:\TEST.txt

goto END

:END

Thank You


Solution

  • See below for comments:

    echo. This script is counting the # of POSTs.
    echo. The POST # value is saved in TEST.txt.
    echo.
    
    call:myPOSTTest
    

    MSDOS doesn't support the call :label syntax

    for /f "tokens=* delims=" %%x in (A:\TEST.txt)  do echo POST# %%x
    

    MSDOS doesn't support the extended for commands

    echo. &pause&goto:eof
    

    MSDOS doesn't support the & command separator or the goto :eof link

    ::--------------------------------------------------------
    ::-- Function section starts below here
    ::--------------------------------------------------------
    
    :myPOSTTest    - here starts my function identified by its label 
    
    set var=0
    
    if EXIST A:\TEST.txt (
         for /f %%x in (A:\TEST.txt) do (set /a var=%%x+1)
    )
    

    MSDOS doesn't support the compound expressions in parentheses or the set /a enhancement

    echo %var% >> A:\TEST.txt
    
    goto END
    
    :END