Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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

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 issueTrusp

There is no for /f in DOS.
=====================================
If at first you don't succeed, you're about average.M2

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!

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.

E:\>(set /a no=ECHO is on.+1 )
and i bet your num.txt contain ECHO is on.
=) jki 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.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |