gpt4 book ai didi

python - 在树莓派上自动运行命令

转载 作者:太空宇宙 更新时间:2023-11-04 12:13:41 25 4
gpt4 key购买 nike

我想知道解决此问题的最佳方法是什么。当 raspberry pi 加载到桌面时,我想运行一堆命令来运行一些 python 脚本和服务。这是我的命令:

cd /var/www/html/
python servocontrol.py


cd /var/www/html/Misc

python temp1.py
python seven_segment.py

sudo /etc/init.d/livestream.sh start

我在大多数帖子中读到的最初方法是通过以下方式将其添加到 rc.local 中:

sudo nano /etc/rc.local

并将确切的命令粘贴到其中,如下所示:

#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi

sleep 15
cd /var/www/html/
python servocontrol.py
cd /var/www/html/Misc
python temp1.py
python seven_segment.py
sudo /etc/init.d/livestream.sh start
exit 0

遗憾的是它没有用。如果有人能指出我遗漏了什么,或者是否需要执行其他步骤才能使它起作用,请善待。如果还有其他方法我也愿意接受!

谢谢

最佳答案

你可以在树莓派上使用 crontab(crontab(“cron table”的缩写)是一个命令列表,这些命令被安排在你的计算机系统上以固定的时间间隔运行。crontab 命令打开 crontab 进行编辑,并且允许您添加、删除或修改计划任务。)

并且您可以为您的脚本创建服务。只需 5 秒搜索即可找到说明,非常简单。

关于python - 在树莓派上自动运行命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48039654/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com