Visual studio code 如何在Visual Studio代码中使用Cmder?
在工作中,有一个企业安全策略,其中所有可执行文件只允许在Visual studio code 如何在Visual Studio代码中使用Cmder?,visual-studio-code,cmder,Visual Studio Code,Cmder,在工作中,有一个企业安全策略,其中所有可执行文件只允许在C:\Program Files或C:\Program Files(x86)中运行 在Visual Studio代码中的settings.json中,使用以下设置: { "terminal.integrated.shell.windows": "C:\\Windows\\Sysnative\\cmd.exe", "terminal.integrated.shellArgs.windows": [ "/k C:
C:\Program Files
或C:\Program Files(x86)
中运行
在Visual Studio代码中的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.
'C:\ProgramFiles' is not recognized as an internal or external command,
operable program or batch file.
'\"C:\Program Files (x86)\Cmder\vendor\init.bat\""' is not recognized as an
internal or external command,
operable program or batch file.
由于Windows很棒的文件/目录命名约定允许空格,因此很难指向程序文件
路径之一
VSCode不喜欢转义空格字符,这段代码给了我错误字符串中无效的转义字符
。当我尝试将属性更改为以下内容时:
{
...
"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.
'C:\ProgramFiles' is not recognized as an internal or external command,
operable program or batch file.
'\"C:\Program Files (x86)\Cmder\vendor\init.bat\""' 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' is not recognized as an internal or external command,
operable program or batch file.
'C:\ProgramFiles' is not recognized as an internal or external command,
operable program or batch file.
'\"C:\Program Files (x86)\Cmder\vendor\init.bat\""' is not recognized as an
internal or external command,
operable program or batch file.
有没有办法将Cmder集成到VSCode中?在搜索了互联网上的答案后,我找不到解决方案,但我找到了答案,并认为我可能会将其发布到这里,让其他人看到,因为我看到来自不同论坛的人都有相同的问题,但没有答案 在Windows中,有一个用于
dir
命令的/X
,该命令说明:
/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.
因此,在C:\
上执行dir/X
命令将显示以下内容:
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)
...
在集成终端中哪个成功加载Cmder:
另一个解决方案是,您可以将cmder位置设置为新路径 只需在settings.json中设置
"terminal.integrated.shell.windows": "C:\\Windows\\system32\\cmd.exe",
"terminal.integrated.shellArgs.windows": [
"/k %CMDER_ROOT%\\vendor\\init.bat"
]
"terminal.integrated.shell.windows": "C:\\Windows\\system32\\cmd.exe",
"terminal.integrated.shellArgs.windows": [
"/k %CMDER_ROOT%\\vendor\\init.bat"
]
{
"window.zoomLevel": 0,
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe",
"terminal.integrated.shellArgs.windows": [
"/k C:\\cmder\\vendor\\init.bat"
]
}
你可以在上找到它,这是我的工作。我的Cmder根目录:
D:\soft\Cmder
,请注意
"terminal.integrated.env.windows": {"CMDER_ROOT": "D:\\soft\\cmder"},
"terminal.integrated.shellArgs.windows": ["/k D:\\soft\\cmder\\vendor\\init.bat"],
将其添加到VSCode设置中。享受吧 另一种方法。
Cmder团队建议在路径中的每个空格前添加一个^
字符,而不是使用8dot3命名方法
示例:
{
"terminal.integrated.shell.windows": "C:\\Windows\\Sysnative\\cmd.exe",
"terminal.integrated.shellArgs.windows": [
"/k C:\\Program Files^ (x86)\\Cmder\\vendor\\init.bat"
]
}
摘自: 路径中的空间 ⚠ 注意:Windows中的命令行解释器在路径中存在一些空格问题,例如
C:\Program Files(x86)\Cmder
。我们不建议在包含空格的路径中安装Cmder
相反,我们建议在不包含任何空格的路径中安装Cmder,例如:C:\apps\Cmder
或C:\tools\Cmder
,以避免与VS-code发生任何冲突
如果出于某种原因确实需要从带有空格的路径启动Cmder,则可能需要在每个空格前添加一个^
符号,以便C:\\Example Directory for Test\\Cmder
在settings.json
文件中变成C:\\Example^Directory^ for^Test\\Cmder
用cmder安装目录替换[cmder\u root]
第二种解决方案
"terminal.integrated.shell.windows": "C:\\Program Files\\cmder\\vendor\\git-for-windows\\bin\\bash.exe",
一个非常简单的解决方案():
使用以下代码在cmder文件夹vscode.bat
的根目录中创建一个文件
@echo off
SET CMDER_ROOT=C:\cmder <--your path to cmder
"%CMDER_ROOT%\vendor\init.bat"
您还可以在cmd
和cmder
之间轻松切换,方法是输入和输出“terminal.integrated.shellArgs.windows”
,我找到的最佳解决方案:
又快又容易
"terminal.external.windowsExec": "C:\\Utils\\Cmder\\Cmder.exe",
"terminal.integrated.shell.windows": "C:\\WINDOWS\\sysnative\\cmd.exe"
"terminal.integrated.shellArgs.windows" : ["/K","C:\\Utils\\cmder\\vendor\\init.bat"],
这个解决方案在开放终端上很好,但会中断通过带有参数(如npm build-lint等)的插件启动的cmd调用 解决方法是创建一个自定义init.bat来包装这些调用,并在sellArgs上引用它 settings.json
"terminal.integrated.shell.windows": "C:\\Windows\\system32\\cmd.exe",
"terminal.integrated.shellArgs.windows": [
"/k %CMDER_ROOT%\\vendor\\init.bat"
]
"terminal.integrated.shell.windows": "C:\\Windows\\system32\\cmd.exe",
"terminal.integrated.shellArgs.windows": [
"/k %CMDER_ROOT%\\vendor\\init.bat"
]
{
"window.zoomLevel": 0,
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe",
"terminal.integrated.shellArgs.windows": [
"/k C:\\cmder\\vendor\\init.bat"
]
}
C:\SoftDev\App\cmder\vendor\vstudio.bat
Windows中的命令行解释器在路径中存在一些空格问题,例如C:\Program Files\Cmder或C:\Program Files(x86)\Cmder。相反,创建一个像“apps”这样的新文件夹,并且使用路径没有像c:\apps这样的空间。@Ari Maulana像一个魔咒一样工作 在变量上添加“CMDER_ROOT”,只需在settings.json中设置即可
"terminal.integrated.shell.windows": "C:\\Windows\\system32\\cmd.exe",
"terminal.integrated.shellArgs.windows": [
"/k %CMDER_ROOT%\\vendor\\init.bat"
]
"terminal.integrated.shell.windows": "C:\\Windows\\system32\\cmd.exe",
"terminal.integrated.shellArgs.windows": [
"/k %CMDER_ROOT%\\vendor\\init.bat"
]
{
"window.zoomLevel": 0,
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe",
"terminal.integrated.shellArgs.windows": [
"/k C:\\cmder\\vendor\\init.bat"
]
}
有两个扩展可以将Cmder包含到VS代码中,但它们在Win 7中都不起作用(我知道已经很旧了),而这里的一些答案对我的案例不起作用 地点详情:
cmd.exe = C:\Windows\System32\cmd.exe
I am using a portable version of Cmder in C:\cmder\Cmder.exe
init.bat = C:\cmder\vendor\init.bat
setting.json = C:\Users\Admin\AppData\Roaming\Code\User\settings.json
这是我的settings.json
"terminal.integrated.shell.windows": "C:\\Windows\\system32\\cmd.exe",
"terminal.integrated.shellArgs.windows": [
"/k %CMDER_ROOT%\\vendor\\init.bat"
]
"terminal.integrated.shell.windows": "C:\\Windows\\system32\\cmd.exe",
"terminal.integrated.shellArgs.windows": [
"/k %CMDER_ROOT%\\vendor\\init.bat"
]
{
"window.zoomLevel": 0,
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe",
"terminal.integrated.shellArgs.windows": [
"/k C:\\cmder\\vendor\\init.bat"
]
}
以及它正常工作的屏幕截图
注意:我不需要将Cmder添加到环境路径中这是执行此操作的新方法“2021” 有关 步骤1: 步骤2:将Cmder保存到C:\drive 步骤3:在VSCode中打开Settings.json(文件-首选项-设置…) 步骤4:输入以下参数:
"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",
您如何在vscode中获得cmder的颜色和外观?我遵循您的步骤,并让cmder在控制台中工作,但仅此而已white@David马丁内斯,试着把配色方案改深一点。请参阅本文:如果你们找不到C:/Windows/Sysnative文件夹,请尝试以下操作:
C:\\Windows\\SysWOW64\\cmd.exe
Fix here:@Adson,谢谢?我已经发布了我的问题的解决方案,而你链接的答案直到我提出我的问题5个月后才出现。用引号围绕整个路径接近但不完全正确。量化标记应围绕包含空格的特定文本块,即“C:\\\\”程序文件(x86)\“\\Cmder\\vendor\\init.bat”
。我知道这个问题已经通过其他方式解决了,但我希望这个小贴士无论如何都是有用的。这里的官方Cmder指南:以前的解决方案对我不起作用,终端中有一条关于无法访问“C:\Config”的错误消息。然而,这个解决方案确实对我有效。根据我的经验,你必须跳出括号和空格。以下是C:\Program Files(x86)\Cmder
对我的工作原理:“C:\\Program^Files^(x86^)\\Cmder”
。设置环境变量也有一些其他好处:工作正常,但在打开新终端时有没有办法删除初始日志记录?