Search code examples
powershellchocolateyappveyor

Redirection to 'NUL' failed: FileStream will not open Win32 devices


I am trying to remove some verbosity from a choco install command within AppVeyor. Here is what I been trying (as suggested here):

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

However it fails with:

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.

So my question is there a way to suppress the verbosity of a choco install command within PowerShell on AppVeyor?


Solution

  • nul is batch syntax. In PowerShell you can use $null instead, as Mathias R. Jessen pointed out in his comment:

    choco install swig > $null
    

    Other options are piping into the Out-Null cmdlet, collecting the output in a variable, or casting it to void:

    choco install swig | Out-Null
    $dummy = choco install swig
    [void](choco install swig)