运行 PowerShell 命令时 WSL 显示大量空行

运行 PowerShell 命令时 WSL 显示大量空行

在 WSL 中,我有时想运行 PowerShell 命令,但它会奇怪地创建大量空行。如何防止这些空行充斥我的控制台或脚本输出?

# Example1 (from Ubuntu or CentOS WSL console):
$ hostname -I | clip.exe   # Use DOS command to collect IP into clipboard
$ powershell.exe /c "get-clipboard"   # Correctly displays the IP, but then also 15 empty lines(!)

# Example2 (from Ubuntu or CentOS WSL console):
# To alter the jarring Windows Event sounds that affect WSL sessions by updating the default sounds
$ powershell.exe '$toChange = @(".Default","SystemAsterisk","SystemExclamation","Notification.Default","SystemNotification","WindowsUAC","SystemHand"); foreach ($c in $toChange) { Set-ItemProperty -Path "HKCU:\AppEvents\Schemes\Apps\.Default\$c\.Current\" -Name "(Default)" -Value "C:\WINDOWS\media\ding.wav" }'

在这两种情况下,控制台都会被 15 行死区所淹没……

我想我会尝试重定向到>/dev/null,但情况更糟,WSL 控制台以一种非常奇怪的方式改变字体并调整屏幕大小。

对此的帮助会很好,因为在 WSL 上下文中,我必须使用 PowerShell 命令调用我正在做的一些事情(更新注册表等)。

相关内容