I just realized I'm executing a bat file at the start at this registry key, that had echo running abc and some other irrelevant things

HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun

So here I've modified that bat file.. it is just one line nothing irrelevant in it.

you see the contents of the bat file.

Here is some output from the cmd prompt showing the situation now which is the same fundamental problem but you should be able to reproduce the problem

The question now is,

  • Why does it say echo sss and not echo sss ttt?
  • How can I suppress the running of cmd or that initialization bat file with the FOR? The FOR statement should really just display "echo g", not "echo sss" or "echo sss ttt".

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
sss ttt
C:\Documents and Settings\Administrator>cd\

C:\>type \blah\startfile.bat <ENTER>
@echo sss ttt   

C:\>  

C:\>for /f %f in ('echo g ^| findstr "g"') do echo %f <ENTER>

C:\>echo sss
sss

C:\>echo g
g

C:\>
link|improve this question

69% accept rate
2  
Can't reproduce. What version of windows is that? – Mat Jul 31 '11 at 18:00
I got "The syntax of the command is incorrect." – Simon Sheehan Jul 31 '11 at 18:25
1  
It works as expected for me (Win 7) - no mystery "echo running" command. – techie007 Jul 31 '11 at 18:56
Out of curiosity, what is the purpose of the caret in your echo line? – jaquer Jul 31 '11 at 19:15
@techie007 xp but just tried it on another machine and it's only on one computer – barlop Jul 31 '11 at 20:46
show 1 more comment
feedback

1 Answer

If you're going to use %f in a batch file, you need to escape it with another %:

for /f %%f in ('echo g ^| findstr "g"') do echo %%f

Put that in your batch file and you should get the results you're looking for.

link|improve this answer
The FOR was not in a batch file. Try reading the question more carefully. Look at the dump from the command prompt. – barlop Nov 3 '11 at 19:06
Whoops. Yep, I see that now. I'll update my answer... – treehead Nov 8 '11 at 17:58
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.