bug? Interaction between Command AutoRun and the FOR /F command

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

AutoRun file contents are included in the FOR /F command.

Without AutoRun, simple FOR /F command
for /f "delims=" %f in ('dir') do echo %f
This simple FOR /F just echos each line produced by the 'dir' command. OK.

Then i set HKCU/Software/Microsoft/Command Processor/AutoRun=c:\profile.bat
so that every time i started a CMD prompt the profile.bat would get run. I
put some DOSKEY command in there.

But now the FOR /F command is strange. The previous example echos al the
lines from my profile.bat, and then all the lines from the 'dir' command.

Seems like a bug to me.
 
I'd guess what is happening is that the for /f is shelling its own
command processor to execute 'dir', which itself executes the autorun.

However, while I'd guess this, it seems to be wrong. If you try
what I thought would workaround it:

for /f "delims=" %f in ('cmd /d /c dir') do echo %f

you still have the problem! So, ... I don't know.

I'd agree with you it's a bug, but your best workaround for now
is probably find a different mechanism to perform the autorun.

Steve Duff, MCSE, MVP
Ergodic Systems, Inc.
 
I can put
@echo off
as the first line in my AutoRun profile.bat, and then refrain from any
'echo' commands in the profile.bat. So far this has fixed the problem in my
limited testing, and may be sufficient for my current application. I wonder
what other side-effects I might encounter.

This seems to be a feature in W2K, WXP, and WXPHome.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top