You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PowerShell执行code .提示“术语未被识别”的问题求助

问题:PowerShell中执行code .提示命令未识别,但CMD可正常运行

现象描述

Windows 10安装最新更新后,在Microsoft Terminal和Wezterm的PowerShell环境执行code .命令时,出现「命令未识别」错误,但该命令在CMD中可正常执行。

报错信息如下:

PS C:\Users\<USER>> code .
C:\Users\<USER>\AppData\Local\Programs\Microsoft : The term 'C:\Users\<USER>\AppData\Local\Programs\Microsoft' is not
recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if
a path was included, verify that the path is correct and try again.
At line:1 char:1
+ C:\Users\<USER>\AppData\Local\Programs\Microsoft VS Code\bin\code.cmd  ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Users\<USER>\...grams\Microsoft:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

即使重启系统、重装VSCode,问题仍未解决。此前环境变量包含C:\Program Files\Microsoft VS Code\bin时,报错提示找不到C:\Program。

环境信息

当前系统环境变量Path内容:

C:\Program Files\Microsoft\jdk-11.0.12.7-hotspot\bin;C:\Program Files\Eclipse Adoptium\jdk-11.0.13.8-hotspot\bin;C:\Program Files\Eclipse Adoptium\jdk-8.0.312.7-hotspot\bin;C:\Program Files\Eclipse Adoptium\jre-8.0.312.7-hotspot\bin;C:\Program Files\Eclipse Adoptium\jre-11.0.13.8-hotspot\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Microsoft VS Code\bin;C:\HaxeToolkit\haxe;C:\HaxeToolkit\neko;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\nodejs\;C:\ProgramData\chocolatey\bin;C:\Program Files\Git\cmd;C:\Program Files\dotnet\;C:\Program Files\WezTerm;%HAXEPATH%;%NEKO_INSTPATH%;C:\Users\<USER>\AppData\Local\Programs\Microsoft VS Code\bin

执行Get-Command code -All的结果:

PS C:\Users\<USER>> Get-Command code -All

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Application     code.cmd                                           0.0.0.0    C:\Users\<USER>\AppData\Local\Programs\Microsoft VS Code\bin\code.cmd
Application     code                                               0.0.0.0    C:\Users\<USER>\AppData\Local\Programs\Microsoft VS Code\bin\code

已尝试的解决方法

  • 重启系统
  • 重装VSCode
  • 执行powershell -NoProfile
  • 执行$env:Path = "$env:LOCALAPPDATA\Programs\Microsoft VS Code\bin;$env:Path"

推测

问题大概率由路径包含空格导致,此前该命令可正常运行,近期才出现异常,可能与Haxelib路径问题相关。

内容的提问来源于stack exchange,提问作者incognitoknose

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 17:52:31