我有一个在启动时运行的脚本,我想使用键盘与脚本进行交互。我已经成功地将其设置为在crontab中运行;但是,该脚本在后台运行,并且我无法使用键盘与该脚本进行交互。这是脚本的简化示例:
def write_to_txt(item_to_write):
with open("my_txt_file.txt", "a") as myfile:
myfile.write('\n'+str(item_to_write))
while True:
keys_to_enter = raw_input()
write_to_txt(keys_to_enter)
请有人能指出我正确的方向吗?
我发现了如何在启动时运行脚本并允许键盘与程序交互。在〜/ .bashrc文件中,我附加了:
sudo python /home/pi/example.py
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句