VS Code 和 WSL 集成终端 - 我无法将 WSL 设置为默认终端

问题描述 投票:0回答:8

在 Visual Studio 代码中选择 WSL 作为默认终端后,我无法打开终端窗口。终端窗口打开,屏幕上出现随机文本,然后终端关闭,并显示一条错误消息:“终端进程终止,退出代码:4294967295”。

有谁知道这是为什么吗?我看过一些 vscode github 问题帖子,但我似乎无法做任何事情。

请参阅我的 settings.json 文件的屏幕截图以及下面发生的情况的 gif:

settings.json

gif of me trying to open a wsl integrated terminal

windows terminal visual-studio-code windows-subsystem-for-linux
8个回答
4
投票

如果 settings.json 文件中有这样一行

"terminal.integrated.shellArgs.windows": ["--login", "-i"],

直接删除它,或者注释掉这一行,就像这样

//"terminal.integrated.shellArgs.windows": ["--login", "-i"],

最后,将terminal.integrated.shell.windows设置更改为这样

"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\wsl.exe",

3
投票

针对 VS Code 1.56.2 更新了答案。我开始在 Settings.json 中看到警告。 这是我成功做到这一点的方法:

设置.json:

 "terminal.integrated.defaultProfile.windows": "WSL",
 "terminal.integrated.profiles.windows": {
        "PowerShell": {
            "source": "PowerShell",
            "icon": "terminal-powershell"            
        },
        "Command Prompt": {
            "path": [
                "${env:windir}\\Sysnative\\cmd.exe",
                "${env:windir}\\System32\\cmd.exe"
            ],
            "args": [],
            "icon": "terminal-cmd"
        },
        "Git Bash": {
            "source": "Git Bash"
        },
        "WSL": {
            "path": [
                "C:\\WINDOWS\\System32\\wsl.exe"
            ],
            "args": [],
            "icon": "terminal-ubuntu-wsl"
        }
  },  

1
投票

尝试从 VSCode 打开 WSL 时出现错误

终端进程“C:\WINDOWS\System32\wsl.exe”终止,退出代码:4294967295。

尝试从 Windows 控制台 (cmd.exe) 执行 C:\WINDOWS\System32\wsl.exe 时出现类似错误

从 Windows 控制台关闭 WSL (wsl --shutdown) 并收到下面的弹出窗口。重新启动 Docker 并可以从 VS Code 打开 WSL。


0
投票

当您的系统中没有安装 Ubuntu 或任何其他 Linux 时,可能会出现此问题。

您可以通过 Windows 中的 Microsoft 商店安装 Ubuntu:

https://www.youtube.com/watch?v=wM-wBciLeDw


0
投票

打开您的 settings.json 文件并将该行更改为:

"terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe"

0
投票

我也有同样的问题,这是我解决的方法

  1. 转到控制面板 -> 程序 -> 打开或关闭 Windows 功能 -> 检查适用于 linux 的 Windows 子系统 how to check list
  2. 接下来去 Microsoft Store 搜索 ubuntu 然后安装,我确实遇到了像你一样的错误,所以我安装了 Ubuntu 20.04 LTS。现在我安装了两种类型的ubuntu
  3. 最后打开cmd -> 右键单击 -> 属性 -> 然后取消选中使用旧版 控制台how to uncheck use legacy console

0
投票

https://stackoverflow.com/a/70035055/5078874

类似的问题

而不是

terminal.integrated.shell.windows

使用这样的设置:

"terminal.external.windowsExec": "wsl.exe"


0
投票

在 vscode 1.85.1 上,只需添加我的设置即可工作:

"terminal.integrated.defaultProfile.windows": "Ubuntu (WSL)",
© www.soinside.com 2019 - 2024. All rights reserved.