why is this FOR doing this?
Moderator: DosItHelp
why is this FOR doing this?
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:\
C:\
C:\WINDOWS\system32>
Why doesn't it display c:\windows\system32 ?
It just displays c:\
Re: why is this FOR doing this?
Interesting.
I don't see that behavior in Vista. What version of Windows are you using
Dave Benham
I don't see that behavior in Vista. What version of Windows are you using
Dave Benham
Re: why is this FOR doing this?
C:\WINDOWS\system32>ver
Microsoft Windows XP [Version 5.1.2600]
C:\WINDOWS\system32>
Microsoft Windows XP [Version 5.1.2600]
C:\WINDOWS\system32>
-
- Expert
- Posts: 442
- Joined: 01 Aug 2010 17:13
- Location: Canadian Pacific
- Contact:
Re: why is this FOR doing this?
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?
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!
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?
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.
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)
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!
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!
-
- Expert
- Posts: 442
- Joined: 01 Aug 2010 17:13
- Location: Canadian Pacific
- Contact:
Re: why is this FOR doing this?
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)
Code: Select all
start cmd /k cd /d "C:\"
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)
Code: Select all
cd /d "C:\"
cls
Re: why is this FOR doing this?
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.
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?
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?
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?
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?
-
- Posts: 76
- Joined: 21 Dec 2011 14:21
Re: why is this FOR doing this?
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:\
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?
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
I know it makes one window. I said it makes 2 processes, I want it to make just one. Look in task manager
-
- Posts: 76
- Joined: 21 Dec 2011 14:21
Re: why is this FOR doing this?
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?
so the question remains