gpt4 book ai didi

powershell - 重定向到 'NUL' 失败 : FileStream will not open Win32 devices

转载 作者:行者123 更新时间:2023-12-04 17:33:22 25 4
gpt4 key购买 nike

我试图从 choco install 中删除一些冗长的内容AppVeyor 中的命令。这是我一直在尝试的(如建议的 here ):

if (Test-Path "C:/ProgramData/chocolatey/bin/swig.exe") {
echo "using swig from cache"
} else {
choco install swig > NUL
}

但是它失败了:

Redirection to 'NUL' failed: FileStream will not open Win32 devices such as
disk partitions and tape drives. Avoid use of "\\.\" in the path.
At line:4 char:5
+ choco install swig > NUL
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : RedirectionFailed

Command executed with exception: Redirection to 'NUL' failed: FileStream will not open Win32 devices such as disk partitions and tape drives. Avoid use of "\\.\" in the path.

所以我的问题是有没有办法抑制 choco install 的冗长AppVeyor 上 PowerShell 中的命令?

最佳答案

nul是批处理语法。在 PowerShell 中,您可以使用 $null相反,正如 Mathias R. Jessen 在评论中指出的那样:

choco install swig > $null

其他选项是管道进入 Out-Null cmdlet,将输出收集到变量中,或将其强制转换为 void :
choco install swig | Out-Null
$dummy = choco install swig
[void](choco install swig)

关于powershell - 重定向到 'NUL' 失败 : FileStream will not open Win32 devices,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34528572/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com