1

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

user3165643
  • 37
  • 1
  • 5
  • I think it wasn't implemented there. But not 100% sure... – Flash Thunder Feb 21 '14 at 17:08
  • Out of curiosity what version of Windows are you running? You mentioned running this in the Windows Command Prompt, but you want to run it in DOS... – ElGavilan Feb 21 '14 at 17:08
  • 2
    I don't think DOS 6.22 supports functions inside the batch file. However, you can do `CALL othercmd.bat` on an external batch file. – lurker Feb 21 '14 at 17:09
  • I ran it in win7,64x. I also have modified a WinPE that executes the batch file with no problem but it takes 3 to 4 mins. DOS is much faster. – user3165643 Feb 21 '14 at 17:11
  • the call command returns a syntax error when its run in DOS6.22 – user3165643 Feb 21 '14 at 17:15
  • DOS 6.22 does not support for /f either. – cup Feb 21 '14 at 17:28
  • So pretty much I have no choice than to stick with my modified WinPE?? thanks for your help guys much appreciated. – user3165643 Feb 21 '14 at 18:36
  • @user3165643 the syntax error is because DOS 6.22 doesn't support `CALL:function` within a batch file. It should support `CALL file.bat` for an external batch file. – lurker Feb 21 '14 at 19:19

2 Answers2

0

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
foxidrive
  • 40,353
  • 10
  • 53
  • 68
0

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.

jeb
  • 78,592
  • 17
  • 171
  • 225