嗨,我正在做一个柠檬条,我想用python或者go或者c或者其他什么东西来管理它,因为我想让程序来管理循环,以及在里面运行的线程。
我发现我可以在我打电话的地方写一个剧本。循环中每个项目中的python脚本,如下
bar.sh
while true
do
python script.py
sleep 1
done然后是script.py
print('%{c}hello')然后我像这样运行它
sh bar.sh | lemonbar这很管用,我在酒吧中间得到了一个hello。但我想做这样的事
bar.py
while True:
print('%{c}hello')然后把它输送到柠檬酒吧
python bar.py | lemonbar这不管用。我有酒吧但上面什么都没有。
我的猜测是,这与pythons打印函数使用的文件描述符相比,与shell zsh使用的文件描述符有关。
编辑:我也尝试过
import sys, time
fd = sys.stdout
while True:
fd.write('hej\n')
time.sleep(1)但这并没有改变什么。
谢谢你阅读我的问题。我希望你能提供帮助:)
发布于 2021-03-16 19:01:37
实际上,我只是通过阅读某人如何实现柠檬酒吧模组来了解如何做到这一点
import time
from subprocess import Popen, PIPE
fd = Popen('lemonbar', stdin=PIPE, stdout=PIPE, encoding='UTF-8')
while True:
time.sleep(1)
fd.stdin.write('%{c}hello')
fd.stdin.flush()
print(fd.stdout.read())诀窍是在写完文件后把它冲洗干净。
所以我也可以这样做
bar.py
import time
import sys
fd = sys.stdout
while True:
fd.write("%{c}hello")
fd.flush()
time.sleep(1)然后像往常一样运行
python bar.py | lemonbarhttps://unix.stackexchange.com/questions/639609
复制相似问题