Discussion:
Is there an equivalent to /dev/null
(too old to reply)
Udo
2007-07-03 13:06:01 UTC
Permalink
Is there an equivalent to /dev/null (like Unix) for redirecting the output of
a command in PowerShell?
Marco Shaw
2007-07-03 13:08:41 UTC
Permalink
Post by Udo
Is there an equivalent to /dev/null (like Unix) for redirecting the output of
a command in PowerShell?
Sure: $null

2# "test"
test
3# "test" > $null
4#
Hal Rottenberg
2007-07-03 13:20:18 UTC
Permalink
Post by Marco Shaw
Sure: $null
There's also the out-null cmdlet which does the same thing but can be
used in a pipeline.

96# "test"
test
97# "test" | out-null
98#
Brandon Shell
2007-07-03 15:07:49 UTC
Permalink
You can also type the response to void

PS> [void]"test"
Post by Hal Rottenberg
Post by Marco Shaw
Sure: $null
There's also the out-null cmdlet which does the same thing but can be
used in a pipeline.
96# "test"
test
97# "test" | out-null
98#
k***@xtra.co.nz
2007-07-03 16:26:02 UTC
Permalink
Post by Udo
Is 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"
}
dreeschkind
2007-07-03 19:24:03 UTC
Permalink
I 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.nz
Post by Udo
Is 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"
}
Bruce Payette [MSFT]
2007-07-05 19:05:27 UTC
Permalink
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 dreeschkind
I 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.nz
Post by Udo
Is 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"
}
Continue reading on narkive:
Loading...