Batch scenario: why doesn't the stdout redirection work in this scenario?

If you open a command prompt and enter this:

echo foobar > nul

it does not print anything, since it nulswallows all its input data. But if you run the command with PowerShell:

powershell "echo foobar" > nul

it will output to the console foobar. Why is this, and what can I do to fix it?

edit: Here is the output $PSVersionTable. Looks like I'm using PowerShell v5.0.

+4
source share
1 answer

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"
+5

Source: https://habr.com/ru/post/1629813/


All Articles