There are, in fact, 4 ways to discard output:
gps | out-null
gps > $null
[void] (gps)
$null = gps
The last one is probably least familiar to people. Anything assigned to
$null is simply discarded.
Generally redirecting to $null is the fastest - the interpreter has special
handing for this case because it makes the code simpler. As a side-effect,
it also turned out to be somewhat faster than piping into out-null. I would
not, however, consider the performance of any of these techniques to be
substantial so use what fits you scenario best. I tend to use redirection to
$null for pipelines and casts to void for expressions.
-bruce
--
Bruce Payette [MSFT]
Windows PowerShell Technical Lead
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.
Post by dreeschkindI wonder if there is any substantial difference between redirecting output to
$null or out-null and casting to [void]. I guess casting might be somewhat
faster than using the pipeline.
--
greetings
dreeschkind
Post by k***@xtra.co.nzPost by UdoIs there an equivalent to /dev/null (like Unix) for redirecting the output of
a command in PowerShell?
yep, others have mentioned some, and therea re more techniques.. i
often use [void]
[void]"hello"
[void]{
1..10
"hello"
}