Solved

Run a DOS command line with spaces in the path

Posted on 2013-11-11
21
7,166 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 92

Expert Comment

by:John Hurst
ID: 39640359
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
ID: 39640372
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
ID: 39640381
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
ID: 39640382
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
ID: 39640386
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
ID: 39640404
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 83

Expert Comment

by:Dave Baldwin
ID: 39640445
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
ID: 39640449
the original post stated progra~1 works which means short names are not disabled
0
 
LVL 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 50 total points
ID: 39640480
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
ID: 39640512
does that short name path work for that program in xp?
0
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 43

Assisted Solution

by:Steve Knight
Steve Knight earned 100 total points
ID: 39640829
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
ID: 39640833
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 33

Expert Comment

by:sarabande
ID: 39641707
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
ID: 39642743
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 83

Expert Comment

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

Expert Comment

by:sarabande
ID: 39644463
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
ID: 39645317
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 33

Expert Comment

by:sarabande
ID: 39645543
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
ID: 39645706
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 83

Expert Comment

by:Dave Baldwin
ID: 39645793
0
 
LVL 1

Author Closing Comment

by:jst3751
ID: 39654330
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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A short article about problems I had with the new location API and permissions in Marshmallow
Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
This tutorial will give a an overview on how to deploy remote agents in Backup Exec 2012 to new servers. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as connecting to a remote Back…
To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…

912 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

17 Experts available now in Live!

Get 1:1 Help Now