powershell - 同时剪辑并显示结果

标签 powershell

如何同时使用clip并显示输出?

每次如果我输入| Clip 在结束行的末尾,输出被复制到剪贴板,但不显示在控制台窗口中。

Get-Date | clip

最佳答案

使用通用参数-ov (-OutVariable)还可以捕获Get-Date的输出一个变量,然后输出该变量:

Get-Date -ov output | clip; $output

如果您调用的命令不是 cmdlet 或高级函数/脚本,因此不支持 -OutVariable,您可以改用此技术:

($output = Get-Date) | clip; $output

这依赖于将变量赋值包含在 (...) 中传递分配的值的事实。

<小时/>

您可以借助自定义函数打包此功能:

Function Write-OutputAndClip { $Input | Write-Output -ov output | clip; $output }

如果您还为其定义了别名,请说 clipecho ...

Set-Alias clipecho Write-OutputAndClip

...您可以简洁地调用它:

Get-Date | clipecho  # copies output to the clipboard *and* echoes it.

关于powershell - 同时剪辑并显示结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46084689/

相关文章:

list - Powershell 列出串行端口 + 说明

json - powershell xml 到 json 空白文件

powershell - puppet 5.3.3和Powershell-返回1而不是[0]之一

mongodb - 为什么这个 msiexec.exe 命令在 powershell 中不起作用?

powershell - 创建使用特定事件日志条目作为触发器的计划任务

powershell - Get-WinEvent 仅获取交互式登录消息

Powershell DSC xChrome 示例在 AzureVM 上失败

powershell - PowerShell-捕获错误未导出到文件外

windows - 带有凭据的 Powershell UNC 路径

regex - Powershell正则表达式替换