powershell - 获取Powershell的剪贴板: '-Raw' option?

标签 powershell text command-line clipboard

从微软文档手册中,我找到了 PowerShell 的“Get-Clipboard”选项。
选项是“-Raw”:

-Raw : Gets the entire contents of the clipboard. Multiline text is returned as a single multiline string rather than an array of strings.

但我找不到添加 '-Raw 的任何区别。
例如,

powershell.exe "Get-Clipboard -Format text " > MyText.txt

powershell.exe "Get-Clipboard -Format text -Raw" > MyText.txt

给出相同的结果。 (不管剪贴板的内容如何) 你能给我一个例子,说明使用“-Raw”选项会有所不同吗?

最佳答案

$tempfile = New-TemporaryFile

@'
some 
different lines 
of text
'@ | Set-Content $tempfile

Get-Content $tempfile | Set-Clipboard

$text = Get-Clipboard

$text.count

3

$text = Get-Clipboard -Raw

$text.Count

1

正如它所说,它是单个字符串,而不是字符串数组。

这里是很多时候它很重要的一个例子。

$text = Get-Clipboard

$text -match 'different'

different lines

$text = Get-Clipboard -Raw

$text -match 'different'

true

关于powershell - 获取Powershell的剪贴板: '-Raw' option?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68399808/

相关文章:

android - 使用 Canvas 绘制时分别更改文本高度和宽度

python - 如何将lxml升级为python2.6

algorithm - 确定陈述中真实案例数量的最短可能方法

sql - 如何使用Powershell 3.0在SQL Server 2008 R2中填写日期?

azure - 如何获取 Azure AD 计算机对象的所有详细信息?

Windows 批处理脚本 : Pipe text into a command line application

command-line - 在 Vim 中打开 URL 的最佳方法

powershell - 我如何在 Powershell 脚本中编写它?

python - 在 python 中,我无法以文本格式导出输出

java - 在 Java 中查询分隔文本文件的最佳工具是什么?