如何通过Python在Gnome中安全地清除两个剪贴板? [英] How to clear both clipboards securely in Gnome, from Python?

查看:86
本文介绍了如何通过Python在Gnome中安全地清除两个剪贴板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Gnome桌面有2个剪贴板,X.org(保存每个选择)和旧版(CTRL + C).我正在编写一个简单的python脚本,最好安全地清除两个剪贴板,因为它可以在复制粘贴密码后完成.

Gnome desktop has 2 clipboards, the X.org (saves every selection) and the legacy one (CTRL+C). I am writing a simple python script to clear both clipboards, securely preferably, since it may be done after copy-pasting a password.

我在这里看到的代码是:

The code that I have seen over here is this:

# empty X.org clipboard
os.system("xclip -i /dev/null")  

# empty GNOME clipboard
os.system("touch blank")  
os.system("xclip -selection clipboard blank")  

不幸的是,由于某些原因,此代码创建了一个名为blank的文件,因此我们必须将其删除:

Unfortunately this code creates a file named blank for some reason, so we have to remove it:

os.remove("blank")

但是,主要的问题是,即使我关闭了终端,通过调用这两个脚本,它也会使xclip进程保持打开状态.

However the main problem is that by calling both of these scripts, it leaves the xclip process open, even after I close the terminal.

我也知道这种方法:

 os.system("echo "" | xclip -selection clipboard")  # empty clipboard

但是,这在剪贴板中留下了\n换行符,因此我也不会将此方法称为有效.

However this one leaves a \n newline character in the clipboard, so I would not call this method effective either.

那如何正确地做呢?

推荐答案

我知道了:

#CLIPBOARD cleaner
subprocess.run(["xsel","-bc"])

#PRIMARY cleaner
subprocess.run(["xsel","-c"])

这将清除两个缓冲区,并且完全不留下任何僵尸进程.感谢所有提出建议的人.

This one cleans both buffers, and leaves no zombie processes at all. Thanks for everyone who suggested some of them.

这篇关于如何通过Python在Gnome中安全地清除两个剪贴板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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