首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在代码中使用Cmder?

如何在代码中使用Cmder?
EN

Stack Overflow用户
提问于 2017-08-18 22:34:56
回答 14查看 48.9K关注 0票数 50

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

在Visual代码中,在settings.json中,使用以下设置:

代码语言:javascript
运行
复制
{
    "terminal.integrated.shell.windows": "C:\\Windows\\Sysnative\\cmd.exe",
    "terminal.integrated.shellArgs.windows": [
        "/k C:\\Program Files (x86)\\Cmder\\vendor\\init.bat"
    ]
}

对于集成终端的...on初始化,我收到以下错误消息:

代码语言:javascript
运行
复制
'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。当我试图将属性更改为:

代码语言:javascript
运行
复制
{
    ...
    "terminal.integrated.shellArgs.windows": [
        "/k C:\\Program\ Files\ (x86)\\Cmder\\vendor\\init.bat"
    ]
}

...I得到以下错误消息:

代码语言:javascript
运行
复制
'C:\ProgramFiles' is not recognized as an internal or external command,
operable program or batch file.

最后,尝试用这样的引号包围路径:

代码语言:javascript
运行
复制
{
    ...
    "terminal.integrated.shellArgs.windows": [
        "/k \"C:\\Program Files (x86)\\Cmder\\vendor\\init.bat\""
    ]
}

...gives me此错误消息:

代码语言:javascript
运行
复制
'\"C:\Program Files (x86)\Cmder\vendor\init.bat\""' is not recognized as an 
internal or external command,
operable program or batch file.

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

EN

回答 14

Stack Overflow用户

回答已采纳

发布于 2017-08-18 22:34:56

在互联网上搜索答案之后,我找不到答案,但我想我可以把它发到这里,让其他人看看,因为我看到来自不同论坛的人有相同的问题,但没有答案。

在Windows中,有一个/X用于dir命令,该命令声明:

代码语言:javascript
运行
复制
  /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:\命令将显示以下内容:

代码语言:javascript
运行
复制
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代码设置以下设置:

代码语言:javascript
运行
复制
{
    "terminal.integrated.shell.windows": "C:\\Windows\\Sysnative\\cmd.exe",
    "terminal.integrated.shellArgs.windows": [
        "/k C:\\PROGRA~2\\Cmder\\vendor\\init.bat"
    ]
}

它成功地在集成终端中加载Cmder:

票数 75
EN

Stack Overflow用户

发布于 2017-11-25 00:23:54

另一个解决方案是可以将cmder位置设置为新路径。

只需设置你的settings.json

代码语言:javascript
运行
复制
"terminal.integrated.shell.windows": "C:\\Windows\\system32\\cmd.exe",
"terminal.integrated.shellArgs.windows": [
    "/k %CMDER_ROOT%\\vendor\\init.bat"
]

你可以在cmder github问题上找到它

票数 24
EN

Stack Overflow用户

发布于 2021-05-29 00:03:13

这是做'2021‘的新方法

这篇文章相关

步骤1:下载Cmder

步骤2:将Cmder保存到C:\驱动器

步骤3:在Settings.json中打开VSCode (文件首选项-设置.)

步骤4:输入以下参数:

代码语言:javascript
运行
复制
"terminal.integrated.profiles.windows": {
    "Cmder": {
      "path": "${env:windir}\\System32\\cmd.exe",
      "args": ["/k", "C:\\cmder\\vendor\\bin\\vscode_init.cmd"]
    }
  },
  "terminal.integrated.defaultProfile.windows": "Cmder",
票数 16
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45765853

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档