如何在 PowerShell 中运行 Code.exe 并在 Path 或 Set-Alias 中重定向错误?

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

我在 USB 驱动器上运行 Visual Studio Code。我想通过为其设置别名或将其放入我的

Code.exe
中,从 PowerShell 运行
Code.exe file1.txt file2.txt
及其常规功能(即通常打开文件 [例如
$env:Path
])。但是,以其中一种方式运行它会
Code.exe
将错误输出到终端:

[main 2024-02-23T21:43:27.202Z] update#setState idle
[16264:0223/144329.744:ERROR:jump_list.cc(300)] Failed to append custom category 'Recent Folders & Workspaces' to Jump List due to system privacy settings.
[main 2024-02-23T21:43:29.758Z] updateWindowsJumpList#setJumpList unexpected result: customCategoryAccessDeniedError
[main 2024-02-23T21:43:29.873Z] WSL is not installed, so could not detect WSL profiles
[main 2024-02-23T21:43:39.634Z] Extension host with pid 7200 exited with code: 0, signal: unknown.

尝试在终端中工作时,这些错误会分散注意力。有没有办法阻止

Code.exe
产生它们?

powershell redirect
1个回答
0
投票

Code.exe
并非设计为直接调用; Visual Studio Code 指定的 CLI 入口点是 code.cmd
 
批处理文件,位于 bin
 所在的 
Code.exe
 子目录中。

code.cmd

 
自动 抑制您看到的异步到达控制台消息。

因此,您应该调用

code.cmd

 / 将 
its 目录添加到 $env:PATH

    

© www.soinside.com 2019 - 2024. All rights reserved.