Solved

Run a DOS command line with spaces in the path

Posted on 2013-11-11
21
7,094 Views
Last Modified: 2013-11-17
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?
0
Comment
Question by:jst3751
  • 6
  • 4
  • 3
  • +5
21 Comments
 
LVL 90

Expert Comment

by:John Hurst
Comment Utility
Are you able to rename TEST SCANNER as TEST_SCANNER ?   Then the short DOS name will work.

... Thinkpads_User
0
 
LVL 1

Author Comment

by:jst3751
Comment Utility
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.
0
 
LVL 22

Assisted Solution

by:Bartender_1
Bartender_1 earned 50 total points
Comment Utility
open a command window, (Start>Run>cmd)
change directories to the "Test" directory

type dir /x

This will tell you the short name for the "Test Scanner" directory.

Hope this helps!

:o)

Bartender_1
0
 
LVL 34

Expert Comment

by:Seth Simmons
Comment Utility
i was going to mention dir /x but i have a feeling the 8.3 name is testsc~1 which he already tried
0
 
LVL 1

Author Comment

by:jst3751
Comment Utility
Actually, dir /x resulted in a BLANK result which according to MS TechNet means it did not know what to do.
0
 
LVL 6

Assisted Solution

by:RaithZ
RaithZ earned 50 total points
Comment Utility
Can you put quotes around the path?  That works for most DOS commands.  As in, where you specify the path of the exe put quotes around the entire path just like you have in the original description.
0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
It is possible that 8.3 file names have been disabled.  http://support.microsoft.com/kb/121007
0
 
LVL 34

Expert Comment

by:Seth Simmons
Comment Utility
the original post stated progra~1 works which means short names are not disabled
0
 
LVL 82

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 50 total points
Comment Utility
I created the path "C:\Program Files\TEST\TEST SCANNER\" on my XP system and then went to a CMD prompt to follow it in 8.3 format and this is what I got.
Short file names
0
 
LVL 34

Expert Comment

by:Seth Simmons
Comment Utility
does that short name path work for that program in xp?
0
The problems with reply email signatures

Do you wish that you could place an email signature under a reply? Well, unfortunately, you can't. That great Exchange/Office 365 signature you've created will just appear at the bottom of an email chain. What a pain! Is there really no way to solve this? Well, there might be...

 
LVL 43

Assisted Solution

by:Steve Knight
Steve Knight earned 100 total points
Comment Utility
another option for you if acceptable - share the directory, then you map anotther drive letter to it, i.e. share the test scanner directory, then make a permanent drive mapping to \\computer\sharename

and then access it from the root of that drive.

there are probably other ways making a link but it depends how this application would see it's path then I suppose.

Steve
0
 
LVL 43

Assisted Solution

by:Steve Knight
Steve Knight earned 100 total points
Comment Utility
Oh and one more, if you are trying to run this from an old 8.3 app then does it have to run an exe or just any command line.  If so point at c:/scripts/myscan.cmd and in there
@echo off
cd /d c:\program files....
scan.exe %1 %2 %3

and it will pass you commandline to the scan.exe

steve
0
 
LVL 32

Expert Comment

by:sarabande
Comment Utility
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
0
 
LVL 1

Accepted Solution

by:
jst3751 earned 0 total points
Comment Utility
To DavidBaldwin: Microsoft in their infinate wisdom must have changed that because that result does not occur with Windows Server 2008 R2.

All other suggestions did not really work, but I did find a work around.

Here is what I ended up doing: The executable is a stand alone executable which you can specificy a number of parameters. One of those parameters is stating where the modules needed are IF they are not in the same directory as the executable or in sub-directories. 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. Then I could include the parament stating where the modules are which include spaces in the path, but by inclosing that parament with quotes the host program just passed to the executable as a parament which then allowed the executable to work as inteneded.
0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
I think that is a good 'temporary' solution.  You can expect "short file names" to disappear in newer versions of Windows.
0
 
LVL 32

Expert Comment

by:sarabande
Comment Utility
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
0
 
LVL 1

Author Comment

by:jst3751
Comment Utility
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.
0
 
LVL 32

Expert Comment

by:sarabande
Comment Utility
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
0
 
LVL 1

Author Comment

by:jst3751
Comment Utility
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.
0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
0
 
LVL 1

Author Closing Comment

by:jst3751
Comment Utility
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.
0

Featured Post

The problems with reply email signatures

Do you wish that you could place an email signature under a reply? Well, unfortunately, you can't. That great Exchange/Office 365 signature you've created will just appear at the bottom of an email chain. What a pain! Is there really no way to solve this? Well, there might be...

Join & Write a Comment

The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now