Computing.Net > Forums > Programming > DOS - For Loop Problem

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

DOS - For Loop Problem

Reply to Message Icon

Name: trusp
Date: January 11, 2009 at 22:37:19 Pacific
OS: DOS
CPU/Ram: Intel DUO
Product: Ms / Ms/e6550
Subcategory: Batch
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: trusp
Date: January 12, 2009 at 00:38:05 Pacific
Reply:

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


0

Response Number 2
Name: Mechanix2Go
Date: January 12, 2009 at 02:12:20 Pacific
Reply:

There is no for /f in DOS.


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

M2


0

Response Number 3
Name: trusp
Date: January 12, 2009 at 02:59:30 Pacific
Reply:

Dos based batch file
for /F "eol=; tokens=1 delims=" %%i in (%Path%) do (set /a no=%%i+1)


0

Response Number 4
Name: klint
Date: January 12, 2009 at 03:09:10 Pacific
Reply:

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!


0

Response Number 5
Name: Judago
Date: January 12, 2009 at 03:19:56 Pacific
Reply:

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.


0

Related Posts

See More



Response Number 6
Name: reno
Date: January 12, 2009 at 03:33:18 Pacific
Reply:

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.


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: DOS - For Loop Problem

DOS for loop www.computing.net/answers/programming/dos-for-loop/17251.html

For loop problem again www.computing.net/answers/programming/for-loop-problem-again/18249.html

pipe into a dos for loop www.computing.net/answers/programming/pipe-into-a-dos-for-loop-/18566.html