Different behavior of cmd on Win7 and XP

146 views Asked by At

I am trying to run following code through cmd.

"C:\Program Files\Beyond Compare 2\BC2.exe" @"C:\New Folder\Myscript.txt" "C:\New Folder\A.txt" "C:\New Folder\B.txt"

This will actually open Beyond Compare and compare two text files.

The problem is ,when i run this code on cmd[Version 6.1.7601] it runs correctly but when i run it on version 5.1.2600 , it shows a fatal error :- Could not find C:/New .

I understand the error is due to space in the name(New Folder) , but why is it running fine on Win 7 .Does two versions of cmd have some difference in the way they accept arguments ?

Content of Myscript.txt :-

file-report layout:side-by-side &
options:display-all &
output-to:%3 output-options:html-color,wrap-word %1 %2
2

There are 2 answers

0
dbenham On

I can't explain why it is not working, but I have some potential solutions

1) Run with the current directory at the location of the files

Since the space is in the folder name, and all files are in the same location, you can avoid the folder name by simply changing directory to that folder and using a relative path.

pushd "c:\new folder"
"C:\Program Files\Beyond Compare 2\BC2.exe" @Myscript.txt A.txt B.txt

Of course this will not work if your files are in different locations, or if the file names have spaces (assuming spaces are really the problem)

2) Use the short 8.3 names

I hate the short 8.3 names because of the many bugs associated with them. But sometimes they can be useful.

You can get the short name of a file or folder by using DIR /X. Or you could use the following in a batch script to programmatically get the short paths.

for %%A in ("C:\New Folder\Myscript.txt") do (
  for %%B in ("C:\New Folder\A.txt") do (
    for %%C in ("C:\New Folder\B.txt") do (
      "C:\Program Files\Beyond Compare 2\BC2.exe" @"%%~fsA" "%%~fsB" "%%~fsC"
    )
  )
)

Of course the above will not do any good if short 8.3 names are disabled on your volume.

4
anurag On

If i understood correctly Raymond's comment ,the parsing is done by Beyond Compare not cmd.

I tried to use

file-report layout:side-by-side &
options:display-all &
output-to:"%3" output-options:html-color,wrap-word "%1" "%2"

and it worked fine on XP but shows error on windows 7 .It seems the beyond compare behaves differently for different OS.