重定向到NUL'失败:FileStream不会打开Win32设备

时间:2015-12-30 11:25:03

标签: powershell chocolatey appveyor

我试图从AppVeyor中的if (Test-Path "C:/ProgramData/chocolatey/bin/swig.exe") { echo "using swig from cache" } else { choco install swig > NUL } 命令中删除一些详细程度。这是我一直在尝试的(建议here):

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中{{1}}命令的详细程度吗?

1 个答案:

答案 0 :(得分:8)

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)