我创建了以下脚本
#!/bin/bash
import subprocess
import sys
from datetime import datetime
from curtsies import Input
locale = datetime.now()
locale = locale.strftime("%m %Y")
locale = locale.split(' ')
MONTH = locale[0]
YEAR = locale[1]
subprocess.Popen(['clear'], shell=False)
subprocess.Popen(['cal', MONTH, YEAR], shell=False)
while True:
with Input(keynames='curses') as input_generator:
for key in input_generator:
if (key is '') or (key is 'q'):
sys.exit()
elif (key is 'KEY_UP') or (key is 'w'):
YEAR = str(int(YEAR)+1)
elif (key is 'KEY_DOWN') or (key is 's'):
YEAR = str(int(YEAR)-1)
elif (key is 'KEY_RIGHT') or (key is 'd'):
if (MONTH == '12'):
MONTH = '1'
YEAR = str(int(YEAR)+1)
else:
MONTH = str(int(MONTH)+1)
elif (key is 'KEY_LEFT') or (key is 'a'):
if (MONTH == '1'):
MONTH = '12'
YEAR = str(int(YEAR)-1)
else:
MONTH = str(int(MONTH)-1)
subprocess.Popen(['clear'], shell=False)
subprocess.Popen(['cal', MONTH, YEAR], shell=False)如果我打开一个终端窗口并输入python3 /path/ to /file.py,它就能完美地工作。然而,我很贪婪,我想用一个命令来打开它,在这个终端运行的情况下创建一个下拉终端。我尝试了以下命令:
xfce4-terminal --geometry 135x40-0+0 --command "python3 ~/.config/polybar/polybar-scripts/calendar-polybar.py" --hide-menubar --hide-toolbar --hide-scrollbar --hide-borders --drop-down --title Calendar但它会立即打开和关闭。由于我的脚本中有一个无限循环,我以为它会一直打开,直到我强制关闭它或简单地按下退出键,但终端在欺骗我。我做错了什么?
发布于 2021-10-27 22:14:07
好吧,我不知道为什么终端在你的情况下不阻塞并等待程序返回,但以下替代方案如预期的那样工作:
xfce4-terminal --geometry 135x40-0+0 --command "sh -c 'python3 ~/.config/polybar/polybar-scripts/calendar-polybar.py'" --hide-menubar --hide-toolbar --hide-scrollbar --hide-borders --drop-down --title Calendar
xfce4-terminal --geometry 135x40-0+0 --hide-menubar --hide-toolbar --hide-scrollbar --hide-borders --drop-down --title Calendar --execute python3 ~/.config/polybar/polybar-scripts/calendar-polybar.pyhttps://stackoverflow.com/questions/69670037
复制相似问题