Page 1 of 2
why is this FOR doing this?
Posted: 20 Dec 2011 16:03
by taripo
C:\WINDOWS\system32>for /f "tokens=*" %f in ('cd') do @ECHO %f <ENTER>
C:\
C:\WINDOWS\system32>
Why doesn't it display c:\windows\system32 ?
It just displays c:\
Re: why is this FOR doing this?
Posted: 20 Dec 2011 16:21
by dbenham
Interesting.
I don't see that behavior in Vista. What version of Windows are you using
Dave Benham
Re: why is this FOR doing this?
Posted: 20 Dec 2011 16:28
by taripo
C:\WINDOWS\system32>ver
Microsoft Windows XP [Version 5.1.2600]
C:\WINDOWS\system32>
Re: why is this FOR doing this?
Posted: 20 Dec 2011 16:33
by orange_batch
Code: Select all
C:\WINDOWS\system32>for /f "tokens=*" %f in ('cd') do @ECHO %f
C:\WINDOWS\system32
C:\WINDOWS\system32>ver
Microsoft Windows XP [Version 5.1.2600]
C:\WINDOWS\system32>
Hmm... try
"delims=" instead of
"tokens=*"?
Does typing just
cd output
C:\? I know this may be specific, but there is the
%CD% variable...
Re: why is this FOR doing this?
Posted: 20 Dec 2011 16:38
by taripo
Since you mention vista works normally..
I just tried it on another computer, also XP SP2 5.2600 and it worked.
So it's just this one computer here.. where it behaves funny!
Re: why is this FOR doing this?
Posted: 20 Dec 2011 16:39
by taripo
C:\WINDOWS\system32>cd <ENTER>
C:\WINDOWS\system32
C:\WINDOWS\system32>for /f %f in ('cd') do echo %f <ENTER>
C:\WINDOWS\system32>echo C:\
C:\
C:\WINDOWS\system32>for /f "delims=" %f in ('cd') do echo %f <ENTER>
C:\WINDOWS\system32>echo C:\
C:\
C:\WINDOWS\system32>
More
C:\WINDOWS\system32>for /f "usebackq delims=" %f in (`cd`) do echo %f <ENTER>
C:\WINDOWS\system32>echo C:\
C:\
C:\WINDOWS\system32>
C:\WINDOWS\system32>for /f %f in ("%cd%") do echo %f <ENTER>
C:\WINDOWS\system32>echo C:\WINDOWS\system32
C:\WINDOWS\system32
C:\WINDOWS\system32>
So just when CD is put in there as a command, there's the issue.
Re: why is this FOR doing this? (solved, kind of)
Posted: 20 Dec 2011 17:06
by taripo
I've found out why it was doing it.
I remember finding out once that the FOR statement runs any initialisation batch file..'cos I once had some output in such a batch file. And the bat file was referenced in an autorun registry entry for the cmd prompt. Any run of the FOR statement ran it and echoed the stuff that bat file echoed. You probably know about that one..
In this case, I had a batch file with the line cd\
Because I don't like the CMD window going into
c:\documents and settings\user>
But I now see this affects the FOR
What to do then?
I do want the cmd prompt to start at C:\>!
But I don't want the FOR statement behaving badly!
Re: why is this FOR doing this?
Posted: 20 Dec 2011 17:37
by orange_batch
I would recommend undoing any registry changes and removing the initialization batch, and instead load command prompt using a script.
Personally I put single letter scripts into my user directory, so I just type x or y or z to initialize different settings. This could be a solution for you if UAC gets in the way.
x.bat (or .cmd)
Re: why is this FOR doing this?
Posted: 20 Dec 2011 18:06
by taripo
I'm on XP.
I often like to launch cmd via start..run..cmd<ENTER>
I just put an icon in the part of the start menu that shows CMD straight away when START is clicked. Hopefully it'll stay there. I think it's 'pinned' there. And i've put an icon for it in the quick launch tray. So I might use that.
I just tried making a cmd.bat in \windows\system32 that could go to a directory, but start..run..CMD<ENTER> doesn't run the bat.
Re: why is this FOR doing this?
Posted: 21 Dec 2011 11:52
by aGerman
taripo wrote:I just tried making a cmd.bat in \windows\system32 that could go to a directory, but start..run..CMD<ENTER> doesn't run the bat.
Save it as
cmd_.bat and run
CMD_ (or choose whatever name ... )
Regards
aGerman
Re: why is this FOR doing this?
Posted: 21 Dec 2011 18:19
by taripo
thanks, I'm now using cmd1.bat
C:\WINDOWS\system32>type cmd1.bat
@cmd.exe /k cd /d c:\rr
C:\WINDOWS\system32>
It's pretty good, but doing start..run..cmd1 <ENTER> runs 2 cmd.exe processes. I'd rather just have one cmd prompt opening to the directory I want, and one cmd.exe process for that window.
How would I do it with only 1 cmd process created?
Re: why is this FOR doing this?
Posted: 29 Dec 2011 11:57
by timbertuck
i just checked your syntax and it appears correct. im using windows xp.
so if your bat file is just one line like so:
cmd1.bat
@cmd.exe /k cd /d c:\
then running this from the Run box, it only opens up one window (and displays the root)
you could also create a shortcut to cmd.exe on your desktop and tweak the properties of the shortcut (after you create the shortcut, right click on the icon, choose properties, from there you can add to the Target; where options go, and Start in; which you would set to the folder you want opened up, so in your case, C:\). If you did it this way, then your string would be "cmd.exe" without any parameters and your start in would be C:\
Re: why is this FOR doing this?
Posted: 29 Dec 2011 13:26
by taripo
I like being able to load it with start..run so start..run..cmd1<ENTER>
I know it makes one window. I said it makes 2 processes, I want it to make just one. Look in task manager
Re: why is this FOR doing this?
Posted: 29 Dec 2011 15:57
by timbertuck
taripo wrote:I know it makes one window. I said it makes 2 processes, I want it to make just one. Look in task manager
my error, apologies for not reading the post completely. and yes your correct, one window, two process'.
ya learn something every day
Re: why is this FOR doing this?
Posted: 29 Dec 2011 16:50
by taripo
so the question remains