Question

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

Was it helpful?

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

OTHER TIPS

A little bit late, but ...

The call :function syntax can be substituted by an additional file for each function or by trampoline code on the batch file entry.

@echo off
for %%P in (/%1.) do if %%P==: goto %1

echo Program started

call %0 :func1
call %0 :func2 With :args 
goto :eof

:func1
echo This is func1 with args: %1, %2, %3
goto :eof

:func2
echo This is func2 with args: %1, %2, %3
goto :eof

:eof

For the arithmetic part in set /a var=%%x+1 you can use an inc.bat or add.bat.

Even reading and processing lines from a text file is possible with old DOS.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top