6

我正在尝试从choco installAppVeyor 中的命令中删除一些冗长的内容。这是我一直在尝试的(如建议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 中抑制命令的冗长?

4

1 回答 1

10

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

choco install swig > $null

其他选项是管道到Out-Nullcmdlet,将输出收集到变量中,或将其转换为void

choco install swig | Out-Null
$dummy = choco install swig
[void](choco install swig)
于 2015-12-30T14:05:26.343 回答