我试图从choco install
AppVeyor中的命令中删除一些冗长.这是我一直在尝试(如这里建议):
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)