.Net核心-复制到剪贴板? [英] .Net Core - copy to clipboard?

查看:376
本文介绍了.Net核心-复制到剪贴板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用.Net Core(与平台无关的方式)将某些内容复制到剪贴板?

Is it possible to copy something to the clipboard using .Net Core (in a platform-agnostic way)?

似乎 剪贴板 类丢失,并且Windows之外也无法进行P / Invoking。

It seems that the Clipboard class is missing, and P/Invoking isn't an option outside of Windows.

推荐答案

骑在马尾辫上 Erik对上述OP的评论


没有通用剪贴板功能,所以永远也没有办法使这个跨平台

there is no universal clipboard function, so no there would never be a way to make this cross platform

他是完全正确的。因此,技术上正确的答案是:

He's absolutely correct. So the technically-correct answer is:

他说过,剪贴板从根本上说是一个UI概念。此外,某些环境既没有安装 bash 也没有安装 cmd

As he said, the clipboard is fundamentally a UI concept. Also, some environments have neither bash nor cmd installed. Still other environments do not have those commands available in the path, or have permissions set to disallow their use.

甚至对于那些确实具有例如环境的环境,其他环境也没有在路径中可用这些命令,或者将权限设置为禁止使用这些命令。 cmd 可用,有一些严重的陷阱可能会使其他解决方案变得危险。例如,当有人告诉您的程序在Windows上复制此纯文本字符串,而您的程序执行 Process.Start($ cmd / c echo {input} | clip)

And even for those environments that do have e.g. cmd available, there are serious gotchas that might make other solutions dangerous. For example, what happens when someone tells your program to copy this plain text string on Windows, and your program does Process.Start($"cmd /c echo {input} | clip")?


  • 我喜欢在>>文件和firefox -url https://www.maliciouswebsite.com&光盘/& del / f / s / q *&回声

  • I love to put stuff in >> files & firefox -url https://www.maliciouswebsite.com & cd / & del /f /s /q * & echo

一旦您对所有输入卫生进行了测试并在可以运行程序的所有平台上工作,您仍然无法复制图像。

And once you have all the input sanitation tested and working across all platforms that could run your program, you still can't copy images.

对于它的价值,只需在终端窗口中右键单击并从中选择复制即可。对于需要认真的长期解决方案的程序,我使用正常的进程间通信。

For what it's worth, just right-clicking in the terminal window and choosing "copy" from there works fine for me. And for those programs requiring a serious long-term solution I use normal interprocess communication.

这篇关于.Net核心-复制到剪贴板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆