【问题标题】:Redirection to 'NUL' failed: FileStream will not open Win32 devices重定向到“NUL”失败:FileStream 不会打开 Win32 设备
【发布时间】:2015-12-30 11:25:03
【问题描述】:

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

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

【问题讨论】:

标签: powershell chocolatey appveyor


【解决方案1】:

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)

【讨论】:

  • 它不是特定于 shell 的。它是NUL 设备的有效本机 Win32 文件名。但大多数 .NET 都不允许它们。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多