Jump to content

Re: Bug in FOR command of cmd.exe


Recommended Posts

Posted

On Sep 12, 4:07 pm, Pegasus wrote:

> Since this is far from a trivial set of batch files, you should ask

> the batch file experts in alt.msdos.batch.nt for advice. They love

> this type of challenge!- Hide quoted text -

>

 

Actually, if you look a little closer you will find those batch files

are really quite simple. They both essentially boil down to executing

some FOR commands that look similar to this:

 

for /f "tokens=4 usebackq" %%a in ('a b c d e f g h') do echo %%a

 

According to the docs, that command should produce the command "echo

d", which should in turn echo the d character to the screen.

In fact that does happen. However, quite often, under some

circumstances that I'm not completely sure of, it also produces a

garbled error message *after* the echo command.

The error message is usually "The system cannot find the file "

followed by some graphics characters, but sometimes it is more messed

up than that.

Sometimes I get this error after executing a command similar to the

above only once, other times it takes more tries.

It appears to be affected but not eliminated by use of "set local

enabledelayedexpansion".

 

Here is a simple test that you can try.

I have tested this on two different machines, both running Windows XP

Service Pack 3 with all critical updates installed.

The results includes garbled error messages on both machines.

Copy the following into a batch file on your machine, then run the

batch file from a command prompt.

 

@echo off

 

for /f "tokens=4 usebackq" %%a in ('a b c d e f g h') do echo %%a

for /f "tokens=4 usebackq" %%b in ('a b c d e f g h') do echo %%b

for /f "tokens=4 usebackq" %%c in ('a b c d e f g h') do echo %%c

for /f "tokens=4 usebackq" %%d in ('a b c d e f g h') do echo %%d

for /f "tokens=4 usebackq" %%e in ('a b c d e f g h') do echo %%e

for /f "tokens=4 usebackq" %%f in ('a b c d e f g h') do echo %%f

for /f "tokens=4 usebackq" %%g in ('a b c d e f g h') do echo %%g

for /f "tokens=4 usebackq" %%h in ('a b c d e f g h') do echo %%h

for /f "tokens=4 usebackq" %%i in ('a b c d e f g h') do echo %%i

for /f "tokens=4 usebackq" %%j in ('a b c d e f g h') do echo %%j

for /f "tokens=4 usebackq" %%k in ('a b c d e f g h') do echo %%k

for /f "tokens=4 usebackq" %%l in ('a b c d e f g h') do echo %%l

for /f "tokens=4 usebackq" %%m in ('a b c d e f g h') do echo %%m

for /f "tokens=4 usebackq" %%n in ('a b c d e f g h') do echo %%n

for /f "tokens=4 usebackq" %%o in ('a b c d e f g h') do echo %%o

for /f "tokens=4 usebackq" %%p in ('a b c d e f g h') do echo %%p

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...