在工作中,有一个企业安全策略,所有可执行文件只允许用完 C:\Program Files
或 C:\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 中,有一个 /X
为 dir
命令,其中指出:
/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:
关于visual-studio-code - 如何在 Visual Studio Code 中使用 Cmder?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45765853/