powershell -> $null 到底做了什么?

标签 powershell io-redirection

我知道这有点愚蠢,但我已经设置了一个自定义配置文件,以 Clear-Host commandlet 结尾,我讨厌以前的 commandlet 的输出在屏幕。我决定将输出发送到 null 以试图抑制输出,例如:

New-Alias -Name note -Value notpad.exe > $null

它似乎在工作,但我不完全确定命令在做什么。这样做可以吗?

最佳答案

> is a redirection operator .这在计算世界中很常见,在 unix (>/dev/null) 和 Windows (> NUL) 中。它通常用于写入文件或设备。在这种情况下,您将无处发送。

在 PowerShell 中执行此操作的其他方法:

Get-Something | Out-Null
[void](Get-Something)
$null = Get-Something

Also here's a performance comparison between the methods .

关于powershell -> $null 到底做了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37056618/

相关文章:

powershell - 如何在Powershell中更改目录并在该目录中运行文件?

linux - 在 Bash 中,如何在命令失败后不创建重定向输出文件

java - 如何制作 bash 包装脚本来执行接受 stdin 并输出到 stdout 的 java jar

c# - 从 C# 调用程序中的非托管 DLL 捕获标准输出

linux - 将 svnadmin dump 的输出重定向到另一台服务器

powershell - 使用PowerShell在同一命令中创建目录和文件

powershell - 使用负载平衡器探测设置更新 Windows Azure 端点

powershell - 有或没有代码块的组对象差异

windows - 如何从批处理脚本将 "2"(无引号)回显到文件?

java - 通过从 Java 执行 PowerShell 脚本来终止服务