gpt4 book ai didi

命令提示符 con 的 Powershell 通讯员?

转载 作者:行者123 更新时间:2023-12-03 09:36:37 26 4
gpt4 key购买 nike

例如,我想在屏幕上显示输出并将其复制到剪贴板。

dir | tee con | clip

上面的代码不起作用,因为 con 在 PowerShell 的文件系统中未被识别为控制台。

还可能有如下场景,

Get-LongLongOutput | 
tee con | # Monitor the intermediate output
Process-LongLongInput |
Process-LongLongInput2 |
.....

最佳答案

您将要收集您的管道数据并将其单独发送到剪贴板,正如@Mathias R. Jessen 所建议的那样。这样做的原因是 Clip 实际上是一个外部应用程序,而不是内置于 PowerShell 中的东西,它使用管道传输给它的信息,除了将信息复制到剪贴板上之外没有任何“输出”。

dir | tee -var data
$data | clip

这(如@Mathias R. Jessen 所建议)将显示您的内容,并将其复制到剪贴板。

或者,您可以在 ForEach 循环中使用 Write-Host 将内容写入屏幕,并且仍然能够将它们通过管道传递给 clip ,但它的格式可能不合需要,大多数人建议尽可能避免使用 write-host。如果你想那样做,你可以使用类似的东西:

dir | ForEach-Object{
Write-Host $_
$_} | Clip

关于命令提示符 con 的 Powershell 通讯员?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31818045/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com