我想从python向rofi/bash传递一个列表。我该怎么做呢?
我试着加入这个名单
choice = "\n".join(links)
chosen = subprocess.check_output("echo " + choice + " | rofi -dmenu -i", shell=True)编辑:我发布的代码有点用。唯一的问题是,所有东西都是一行。那么如何将python列表转换为rofi可以处理的bash列表呢?
发布于 2020-09-25 21:44:42
我能够找到一个使用Popen类https://docs.python.org/3.4/library/subprocess.html#popen-objects的解决方案,这不是最好的解决方案,我打赌还有更好的解决方案。
我无法使用rofi包对其进行测试。请让我知道这对我有帮助。
from subprocess import Popen,PIPE
links = ["1","2"]
choice = "\n".join(links)
p1 = Popen(["echo", choice], stdout=PIPE)
p2 = Popen(["rofi", "-demnu", "-i"], stdin=p1.stdout, stdout=PIPE)
p1.stdout.close()
output = p2.communicate()[0]发布于 2020-09-26 01:22:34
我自己找到了answe:
choices = "\n".join(links)
chosen = check_output("echo '" + choices + "' | rofi -dmenu", shell=True)列表rofi或dmenu读取的类型需要用\n分隔,并且整个内容需要在qutoes中。
https://stackoverflow.com/questions/64064520
复制相似问题