Computing.Net > Forums > Programming > %CD% weirdness

%CD% weirdness

Reply to Message Icon

Original Message
Name: Mechanix2Go
Date: July 4, 2007 at 10:04:32 Pacific
Subject: %CD% weirdness
OS: w2k sp3
CPU/Ram: PIII 933/256MB
Model/Manufacturer: brand x
Comment:

When I echo %CD% the fir gets truncated. Screen shot:

=========================================
O:\SCORPI~1>echo %cd%
O:\SCORPI~1

O:\SCORPI~1>dir ..\sco*
Volume in drive O is 250-2
Volume Serial Number is 9874-B328

Directory of O:\

04-07-2007 23:57 <DIR> Scorpions - Acoustica



=====================================
If at first you don't succeed, you're about average.

M2



Report Offensive Message For Removal


Response Number 1
Name: IVO
Date: July 4, 2007 at 13:08:55 Pacific
Reply: (edit)

Hi M2,

Happy Birthday America!

What you are facing is caused by the action of Command.com as your actual command processor. I try to explain better...

If your prompt is ruled by Command, while you get the NT display by Dir and other commands, you CAN'T use the LFN notation for folders/files, and actually your prompt is in 8.3 short notation.

Set up two NT consoles, one typing in the shortcut wizard cmd.exe and the other command.com and then experiment the same CD and Echo %CD% in both: results are not the same.

You can convert a DOS like prompt into NT by instancing a secondary processor by typing CMD and vice versa.



Report Offensive Follow Up For Removal

Response Number 2
Name: Mechanix2Go
Date: July 4, 2007 at 13:40:32 Pacific
Reply: (edit)

Hi IVO,

I am using smd. Screen shot:
=============================
O:\SCORPI~1>echo %CD%
O:\SCORPI~1

O:\SCORPI~1>set c
CommonProgramFiles=C:\Program Files\Common Files
COMPUTERNAME=BIG933
ComSpec=C:\WINNT\system32\cmd.exe
=============================
Oddly, it works here:

C:\Program Files>echo %CD%
C:\Program Files
=======================
and here:

S:\my test>echo %CD%
S:\my test
==================
O: and S: are NTFS; C: is FAT32.

Beats me.


=====================================
If at first you don't succeed, you're about average.

M2



Report Offensive Follow Up For Removal

Response Number 3
Name: IVO
Date: July 4, 2007 at 14:18:28 Pacific
Reply: (edit)

Hi M2,

How did you get the 8.3 prompt (O:\SCORPI~1>) from your native one?

I'm interested in your strange case as it is quite mysterious... but I need to investigate about, so more info may help.


Report Offensive Follow Up For Removal

Response Number 4
Name: Mechanix2Go
Date: July 5, 2007 at 04:43:24 Pacific
Reply: (edit)

Found the problem.

With a fresh CMD prompt, everything works as expected. UNTIL I run LIST.COM, after which LFNs get truncated.

Same thing if I run cpp. I guess NTVDM thinks that if I run a DOS app it means I want to go back the the stone age. LOL


=====================================
If at first you don't succeed, you're about average.

M2



Report Offensive Follow Up For Removal

Response Number 5
Name: Razor2.3
Date: July 5, 2007 at 21:39:42 Pacific
Reply: (edit)

Yeah, if you're using short names, %CD% is set to the short name. Basically, whatever prompt $p reports. I don't know how to "fix" it from a batch file.

Oh, and IVO, here's something for you to try:
cd /d c:\progra~1

It works unless you've issued the command
fsutil behavior set disable8dot3 1
Behold the power of backwards compatibility.


Report Offensive Follow Up For Removal


Response Number 6
Name: Mechanix2Go
Date: July 5, 2007 at 22:13:07 Pacific
Reply: (edit)

'fsutil' is not recognized as an internal or external command
operable program or batch file.

[w2k]

I will try disabling command.com; but not until I image the drive.


=====================================
If at first you don't succeed, you're about average.

M2



Report Offensive Follow Up For Removal

Response Number 7
Name: Razor2.3
Date: July 5, 2007 at 23:02:01 Pacific
Reply: (edit)

Ah. Fsutil is included with WinXP, and some version of it is included in some Win2K Resource Kit.

I should also probably mention that disabling 8.3 with fsutil will break 16-bit apps. Hard.


Report Offensive Follow Up For Removal

Response Number 8
Name: Mechanix2Go
Date: July 6, 2007 at 02:43:41 Pacific
Reply: (edit)

What do you think about disabling command.com?


=====================================
If at first you don't succeed, you're about average.

M2



Report Offensive Follow Up For Removal

Response Number 9
Name: Razor2.3
Date: July 6, 2007 at 03:37:09 Pacific
Reply: (edit)

What's happening is a compatibility feature of cmd.exe, not a running instance of command.com.

You could open up the process viewer of your choice, and you'll see ntvdm.exe running. That's your 16-bit environment. If the viewer of your choice had a tree view, you'd see it's a child of cmd. (It continues to run, even if no 16-bit programs are going.)

Example (Me = blue, PC = red, Comments = default):

Fri 07/06/2007 6:22:52.47 +
C:\>pd "Program Files"


Fri 07/06/2007 6:22:54.02 ++
C:\Program Files>command
Microsoft(R) Windows DOS
(C)Copyright Microsoft Corp 1990-2001.


Fri 07/06/2007 6:23:17.19
C:\PROGRA~1>pst

(Truncated output)

|.+-2872: cmd.exe
|...+-2208: wscript.exe
|...+-3080: IEXPLORE.EXE
|...+-2152: ntvdm.exe
<-- Command.com's environment
|.....+-2844: cmd.exe
<-- my command
|.......+-3148: cscript.exe

(Truncated output)

Fri 07/06/2007 6:23:22.85
C:\PROGRA~1>exit


Fri 07/06/2007 6:23:26.30 ++
C:\PROGRA~1>pst

|.+-2872: cmd.exe
|...+-2208: wscript.exe
|...+-3080: IEXPLORE.EXE
|...+-2152: ntvdm.exe
<-- Still running
|...+-4028: cscript.exe
<-- My command

Fri 07/06/2007 6:23:27.55 ++
C:\PROGRA~1>
<-- $P still sucks, even though I got back my $+.

I'm not sure where I'm going with that example, other than to show we're all on the same page.

If you disabled ntvdm, your problem should be fixed; whatever 16-bit program you're using (LIST, wasn't it?) would crash before it gets a chance to change your prompt.



Report Offensive Follow Up For Removal

Response Number 10
Name: Mechanix2Go
Date: July 6, 2007 at 04:10:26 Pacific
Reply: (edit)

I dunno process viewer, but I tried shelling out of LIST, VDE and QBASIC and in each case the COMSPEC was:

COMSPEC=C:\WINNT\SYSTEM32\COMMAND.COM



=====================================
If at first you don't succeed, you're about average.

M2



Report Offensive Follow Up For Removal

Response Number 11
Name: Razor2.3
Date: July 6, 2007 at 04:39:22 Pacific
Reply: (edit)

Ntvdm is the virtual machine, which uses command.com for its shell (think DOS 6.22 and down). Disabling command.com would probably crash ntvdm, or (worst case) cause it to freeze without crashing. I don't know which; I haven't tried it.

That would explain why you would see command.com as the shell.

Killing either one would keep the emulator from running [programs].

Of course, you could just avoid all of this by prefixing LIST with cmd /c.


Report Offensive Follow Up For Removal

Response Number 12
Name: Mechanix2Go
Date: July 6, 2007 at 23:25:06 Pacific
Reply: (edit)

cmd /c list

still trashes LFNs


=====================================
If at first you don't succeed, you're about average.

M2



Report Offensive Follow Up For Removal






Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: %CD% weirdness

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes Today.
Discuss in The Lounge