Note. I assume that you are invoking your command from cmd.exe and not from PowerShell, which is consistent with the symptoms that I see.
, PS (PowerShell) v5 ( v3, , 4), , PS , cmd.exe .
, - , .
PowerShell - , echo, Write-Output - .
PS >NUL PowerShell.
, v5 NUL, .
:
v2, :
powershell -version 2 "echo foobar" > NUL
:
powershell "echo foobar" > "%TEMP%\NUL-bug-workaround" & del "%TEMP%\NUL-bug-workaround"