简体   繁体   English

Win7和XP上cmd的不同行为

[英]Different behavior of cmd on Win7 and XP

I am trying to run following code through cmd. 我试图通过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 . 问题是,当我在cmd [Version 6.1.7601]上运行此代码时,它可以正确运行,但是当我在5.1.2600版本上运行时,它显示出致命错误:-找不到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 ? 我知道错误是由于名称(New Folder)中的空格引起的,但是为什么它在Win 7上运行良好。两个版本的cmd接受参数的方式是否有所不同?

Content of Myscript.txt :- Myscript.txt的内容:-

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

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 1)使用文件所在位置的当前目录运行

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 2)使用简短的8.3名称

I hate the short 8.3 names because of the many bugs associated with them. 我讨厌简短的8.3名称,因为与它们相关的许多错误。 But sometimes they can be useful. 但是有时候它们会有用。

You can get the short name of a file or folder by using DIR /X . 您可以使用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. 当然,如果您的卷上禁用了短的8.3名称,则上述方法将无济于事。

If i understood correctly Raymond's comment ,the parsing is done by Beyond Compare not cmd. 如果我正确理解了Raymond的评论,则解析将由Beyond Compare而不是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. 并且它在XP上运行良好,但在Windows 7上却显示错误。似乎无法比拟的行为在不同的OS上有所不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM