【问题标题】:Windows10 cmd.exe default directory different to Windows7Windows 10 cmd.exe 默认目录不同于 Windows 7
【发布时间】:2021-05-15 20:34:25
【问题描述】:

当您已经在 Win7 和 Win10 之间的 shell 中执行 cmd.exe 时,我发现默认目录的行为有所不同。

Windows 7:

C:\projects\test>ver

Microsoft Windows [Version 6.1.7601]
     
C:\projects\test>cmd.exe
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
     
C:\projects\test>exit
     
C:\projects\test>

Windows 10:

C:\projects\test>ver
 
Microsoft Windows [Version 10.0.18363.1316]
 
C:\projects\test>cmd.exe
Microsoft Windows [Version 10.0.18363.1316]
(c) 2019 Microsoft Corporation. All rights reserved.
 
C:\Users\john>exit
 
C:\projects\test>

我面临的问题是,这种行为差异导致一些 3rd-party 脚本失败,因为它假设当 cmd.exe 执行时,它运行在默认目录而不是用户家中目录或C:\Users\xxxx

例如:

  1. yarn install 当目录包含一个依赖于 phantomjs-prebuilt 的 package.json 时。它最终在C:\Users\xxxx 中而不是在node_modules\karma-phantomjs-launcher\node_modules\phantomjs_prebuilt 目录中寻找install.js
  1. Maven 的 maven-javadoc-plugin 在执行 jar 目标时动态创建一个 javadoc.bat 并且该 BAT 文件专门调用 cmd.exe 来执行 javadoc。本质上,由于这种行为,在 Windows10 中,来自 maven 构建的 javadoc 执行失败。

【问题讨论】:

    标签: windows-7 windows-10 phantomjs maven-javadoc-plugin


    【解决方案1】:

    找出原因。在我工作的地方有一个注册表设置适用于公司范围内的所有 Windows10 设备。

    HKEY_CURRENT_USER\Software\Microsoft\Command Processor 中的一个自动运行键,用于将目录更改为用户的主目录。

    删除此键,然后行为一致。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多