DOS - For Loop Problem

Ms / Ms/e6550
January 11, 2009 at 22:37:19
Specs: DOS, Intel DUO
Hi,

I have a problem with my batch file.

I ran my script to get the next process number from the Num file.
Here the problem is that instead the value in the text file "ECHO is on." is placed to the temp variable.

Batch Command:
E:\>for /F "eol=; tokens=1 delims=" %%i in (C:\Num.txt) do (set /a no=%%i+1 )

CLI Output:
E:\>for /F "eol=; tokens=1 delims=" %%i in (C:\Num.txt) do (set /a no=%%i+1 )
E:\>(set /a no=ECHO is on.+1 )
Missing operator.

Num.txt - Is the text file which contains the process number.
I think the problem may be in for loop.

Please help me out in this issue asap.

Trusp


See More: DOS - For Loop Problem

Report •


#1
January 12, 2009 at 00:38:05
This Example contains the Similar Script

@echo on
set Path=C:\Temp.txt
for /f "eol=; tokens=1 delims=" %%i in (%Path%) do (set /a no=%%i+1)
echo First %no%
set no=1
echo %no%> %Path%
for /f "eol=; tokens=1 delims=" %%i in (%Path%) do (set /a no1=%%i+1)
echo Final %no1%

Here I am trying to read a number from file and after that trying to set it as 1.
But its setting as "ECHO is on".

I cant find the reason for it.
set no=1
echo %no%> %Path%
Please help me out in this issue

Trusp


Report •

#2
January 12, 2009 at 02:12:20
There is no for /f in DOS.


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#3
January 12, 2009 at 02:59:30
Dos based batch file
for /F "eol=; tokens=1 delims=" %%i in (%Path%) do (set /a no=%%i+1)

Report •

Related Solutions

#4
January 12, 2009 at 03:09:10
I think the problem may be in your num.txt file - perhaps it doesn't contain what you think it contains. And I bet your operating system is not DOS!

Report •

#5
January 12, 2009 at 03:19:56
I'm almost certain the problem comes from handle redirection as stated in the duplicate thread.

echo %no%> file

example:
C:\Documents and Settings\JUDAGO>set no=3
C:\Documents and Settings\JUDAGO>echo %no%>file
ECHO is on.


Remedy

> file echo %no%


And another thing, technically it is a NT command script and not a DOS batch file. A .bat file is called a "MS-DOS Batch file" because .bat is included for compatibility reasons. .cmd is the proper file extension for command scripts in nt,2k,xp and all releases thereafter.

I suggest that you don't state your os as dos unless that is what your using, which you are obviously not. Just state the version of windows your using.


Report •

#6
January 12, 2009 at 03:33:18
E:\>(set /a no=ECHO is on.+1 )

and i bet your num.txt contain ECHO is on.
=) jk

i just knew changing the extension from .bat to .cmd does works. great! yet somehow its still unusual for me to have batch file with .cmd extension.


Report •


Ask Question