visual-studio-code - 如何在 Visual Studio Code 中使用 Cmder?

标签 visual-studio-code cmder

在工作中,有一个企业安全策略,所有可执行文件只允许用完 C:\Program FilesC:\Program Files (x86) .

在 Visual Studio Code 中,在 settings.json 中,使用以下设置:

{
    "terminal.integrated.shell.windows": "C:\\Windows\\Sysnative\\cmd.exe",
    "terminal.integrated.shellArgs.windows": [
        "/k C:\\Program Files (x86)\\Cmder\\vendor\\init.bat"
    ]
}

...在集成终端初始化时,我收到以下错误消息:
'C:\Program' is not recognized as an internal or external command, 
operable program or batch file.

由于 Windows 令人敬畏的文件/目录命名约定允许空格,因此很难指向 Program File 之一。路径。

当你转义空格字符时,VSCode 不喜欢它,这段代码给了我错误 Invalid escape character in string .当我尝试将属性更改为:
{
    ...
    "terminal.integrated.shellArgs.windows": [
        "/k C:\\Program\ Files\ (x86)\\Cmder\\vendor\\init.bat"
    ]
}

...我收到以下错误消息:
'C:\ProgramFiles' is not recognized as an internal or external command,
operable program or batch file.

最后,尝试用这样的引号将路径括起来:
{
    ...
    "terminal.integrated.shellArgs.windows": [
        "/k \"C:\\Program Files (x86)\\Cmder\\vendor\\init.bat\""
    ]
}

...给我这个错误信息:
'\"C:\Program Files (x86)\Cmder\vendor\init.bat\""' is not recognized as an 
internal or external command,
operable program or batch file.

有没有办法在 VSCode 中集成 Cmder?

最佳答案

在网上搜索答案后,我找不到解决方案,但我想通了,并认为我可以将其发布在这里供其他人查看,因为我看到来自不同论坛的人有相同的问题,但没有回答。

在 Windows 中,有一个 /Xdir命令,其中指出:

  /X          This displays the short names generated for non-8dot3 file
              names.  The format is that of /N with the short name inserted
              before the long name. If no short name is present, blanks are
              displayed in its place.

所以,做一个 dir /X命令在 C:\显示以下内容:
C:\>dir /X
 Volume in drive C is OSDisk
 Volume Serial Number is XXXX-XXXX

 Directory of C:\

...
08/17/2017  08:02 PM    <DIR>          PROGRA~1     Program Files
08/09/2017  03:58 PM    <DIR>          PROGRA~2     Program Files (x86)
...

您可以使用目录短名称 PROGRA~2替换 Program Files (x86) ,并在您的 settings.json 中进行以下设置对于 VS 代码:
{
    "terminal.integrated.shell.windows": "C:\\Windows\\Sysnative\\cmd.exe",
    "terminal.integrated.shellArgs.windows": [
        "/k C:\\PROGRA~2\\Cmder\\vendor\\init.bat"
    ]
}

这确实在集成终端中成功加载了 Cmder:

Image of Cmder being successfully loaded in the VS Code integrated terminal.

关于visual-studio-code - 如何在 Visual Studio Code 中使用 Cmder?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45765853/

相关文章:

git - cmder/git 将 (master -> origin) 显示为分支而不是 (master)

conemu - 自Windows更新以来,Conemu不适用于wsl

alias - 指挥官 : how to use an alias in another alias?

visual-studio - F# 断点仅在抛出异常后才起作用

git - 如何在 VSCode 的集成终端中启用 git 自动完成?

vim - cmder 使用 ssh 以替换模式启动 vim

visual-studio - Visual Studio 和 Visual Studio Code 中的相同快捷方式

visual-studio-code - 如何缩进/取消缩进一行?

settings - 有没有办法更改 Visual Studio Code 的扩展文件夹位置?