Run Terminal Commands on Raspberry Startup

*爱你&永不变心* 提交于 2021-01-29 07:20:17

问题


I am working on a project in which I am using curses and pygame librarie, my python program/script can only be run through using terminal otherwise this error occurs

fd=_sys.__stdout__.fileno())
_curses.error: setupterm: could not find terminal

I want to run my program on startup of Raspberry pi by using these two commands

cd Desktop
python test.py

I am aware of rc.local but unable to run this....(first open terminal and then run these 2 commands in order to run my script)


回答1:


Running on startup, e.g., using rc.local, there's at least two problems:

  • the TERM environment variable is not set (giving the setupterm: could not find terminal message)
  • you won't be able to handle input, only output...



回答2:


I spent around 1 day and test 4 solutions for Linux/raspberry startup run script issues. Then here is the solution (I choose crontab)

  1. open crontab (use linux@crontab -e -> not use sudo crontab -e ... thats could be error in future some access for script etc.)

pi@ crontab -e

Then choose nano and edit like this... It is tricky, ı found after test may be more than 10x times:

@reboot cd /home/pi/beetool && /usr/bin/python3 run.py &

My code is waiting for me under /home/pi/beetool. If you don't change the directory that occurs error.

And my code uses infinite loop so I have to finish with "&" as you see above.

So I hope that helps someone, too ...



来源:https://stackoverflow.com/questions/52647466/run-terminal-commands-on-raspberry-startup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!