从微软文档手册中,我找到了 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/