在Boot Raspberry Pi上的前景中运行脚本 [英] Run Script in Foreground On Boot Raspberry Pi

查看:92
本文介绍了在Boot Raspberry Pi上的前景中运行脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在启动时运行的脚本,我想使用键盘与脚本进行交互。我已成功将其设置为在crontab中运行;但是,该脚本在后台运行,我无法使用键盘与该脚本进行交互。这是脚本的简化示例:

I've a script to run on boot and I'd like to use the keyboard to interact with the script. I've successful set this up to run in crontab; however, the script runs in the background and I can't use the keyboard to interact with the script. Here's a simplified example of the script:

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)

请有人能指出正确的方向吗?

Please could someone point me in the right direction?

推荐答案

我发现了如何在启动时运行脚本并允许键盘与程序交互。在〜/ .bashrc文件中,我附加了:

I found out how to run the script on boot and allow the keyboard to interact with the program. To the ~/.bashrc file, I appended:

sudo python /home/pi/example.py

这篇关于在Boot Raspberry Pi上的前景中运行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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