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

1

7

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?

Knotted answered 30/12, 2015 at 11:25 Comment(3)
choco install swig > $nullEmbouchure
#5260625Gentilism
Throwing this out there - you should add -y to the argument as it may fail to finish installing depending on the version of choco.Subacid
C
12

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)
Coxswain answered 30/12, 2015 at 11:25 Comment(1)
It is not specific to the shell. It is a valid native Win32 filename for the NUL device. But most of .NET does not allow them.Googol

© 2022 - 2024 — McMap. All rights reserved.