Link to home
Start Free TrialLog in
Avatar of John Tolmachoff
John TolmachoffFlag for United States of America

asked on

Run a DOS command line with spaces in the path

I am trying to run a command line from a program that can not use long names or spaces.

The path to the file being called is "C:\Program Files\TEST\TEST SCANNER\scan.exe"

The "Program Files" easily converts to Progra~1 but because the third level only has 4 charachters and then a space, it will not work. I have tried TEST~1 and TESTSC~1 and it still errors.

Any ideas or suggestions?
Avatar of John
John
Flag of Canada image

Are you able to rename TEST SCANNER as TEST_SCANNER ?   Then the short DOS name will work.

... Thinkpads_User
Avatar of John Tolmachoff

ASKER

No I would have to completely uninstall the program and reinstall pointing to a different directory that does not have the space in it. While that is an option, I am trying to avoid that.
SOLUTION
Avatar of Bartender_1
Bartender_1
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i was going to mention dir /x but i have a feeling the 8.3 name is testsc~1 which he already tried
Actually, dir /x resulted in a BLANK result which according to MS TechNet means it did not know what to do.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It is possible that 8.3 file names have been disabled.  http://support.microsoft.com/kb/121007
the original post stated progra~1 works which means short names are not disabled
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
does that short name path work for that program in xp?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I am trying to run a command line from a program that can not use long names or spaces.
can you post the command line which failed? I once had similar problems where I thought the program can't handle long names but actually it was a problem with quoting the path.

Sara
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think that is a good 'temporary' solution.  You can expect "short file names" to disappear in newer versions of Windows.
if the program can handle "C:\Program Files\TEST\scan.exe" but not "C:\Program Files\TEST\TEST SCANNER\scan.exe" it obviously can handle long name "Program Files" space character in name in the first case. it is not very likely that it should not be able to handle it in the second case.

I would guess that the folder "TEST SCANNER" either was not be passed correctly within quotation marks at the command line, or - less likely though - that the program that receives the path cannot handle the a long filename with spaces in the final folder only.

Sara
Sara, that is not true. I have just done some additional tests and you can check for yourself.

Any one on a Windows Server 2008 R2 go to "C:\Program Files (x86)\" directory and do a "dir /x" and see what you get for the directory "C:\Program Files (x86)\MSXML 4.0\"

You do not get the short name do you. The space is at character 6.

Now go to "C:\Program Files\VMware\" and do a "dir /x" and see what you get for the directory "C:\Program Files\VMware\VMware tools\"

You do get a short name this time. The space is character 7 which is replaced anyways.

Now try creating a directory called "TEST TEST TEST" at the root of C, then do a "dir /x" at the root of C and what do you get? Again, you do not get the short name.

This seems like a bug in Windows Server 2008 R2. On a Windows 7 Professional it works just fine.
in my opinion the problem with C:\Program Files (x86) is that it is a symbolic link and not a folder. I would guess because of that a short filename was not supported (what indeed is a bug).

my concern did not apply to paths with short names. i wondered because of two contradicting assertions in your comments:

(1)
I am trying to run a command line from a program that can not use long names or spaces.
The path to the file being called is "C:\Program Files\TEST\TEST SCANNER\scan.exe"

(2)
So I copied the executable one level up which got rid of that space problem. At that point it could be called by the host program without any errors.

if (2) was done with the path of (1) you would still have a space problem.

note, i don't know any program made in the last ten years that has problems with long file names and spaces. that were issues of the nineties of the last century and you rarely would run programs  which date back to those times.

on the other hand, a command line interpreter has problems if arguments were passed that were not properly quoted. any space character that was not within quotes would make two arguments out of one. this behavior didn't change ever. my doubt was whether you were sure that the path you pass to the program properly was put within quotation marks?

as told, it is only a doubt. of course, you should ignore my remark if it was baseless.

Sara
Sara, "C:\Program Files (x86)\" is a real actual folder, not any link. It is the Windows directory for installed 32 bit programs on a 64 bit OS.

To all, I have received some eye opening information on another forum:

One possible explanation is – someone turned off the 8.3 filename creation for performance reasons for THAT partition at some LATER date. That will NOT REMOVE any “old” 8.3 filenames created prior, but will not cease to create any NEW 8.3 filenames for newly added files/folders.

Take a look at the directories that DO have 8.3 filenames – when were they created? At that time, that feature was still active on THAT partition.

Now, compare that other directories on the SAME partition that do lack 8.3 filenames – do they have NEWER creation dates?


So I did more investigating on my servers and here is what I found:

The creation date of the directories that ARE getting short names are in the 2009 range. The creation date of the "TEST TEST TEST" directory is July 2011. Checking the registry key I now see that short file name creation is disabled. I had assumed that it was enabled as I was seeing some 8.3 file names created.

So it then appears that HKLM\SYSTEM\CurrentControlSet\Control\FileSystem\NtfsDisable8dot3NameCreation must be OFF (set to "0") at the time the folder is created for it to get an appropriate short name as needed.
None of the offered suggestions resulted in a working solution. However they tried. I ended up coming up with a work around that resulted in a working solution.