I have a problem with start python script just after startup raspberry pi. I've try with init.d, rc.local and cron. No way worked.
My script waiting for input and save it to file:
import datetime
path = '/my/path/to/file.csv'
while 1:
name = input()
date = datetime.datetime.now().strftime('%Y-%m-%d %H-%M-%S')
presence = str(name) + ";" + str(date) + '\n'
print(presence)
file = open(path, "a+")
file.write(presence)
file.close()
How I can run it after startup and the script will be waiting for input all the time.
Cron:
sudo crontab -e
@reboot python /home/pi/Desktop/myscript.py
rc.local:
python /home/pi/Desktop/myscript.py
Note that
input()reads from stdin. A program launched from init.d, rc.local, or cron will have stdin open on /dev/null. Which meansinput()will raise a EOFError. Also,input()evals the line it reads. Which is probably not what you want. So you have at least two problems with your code.I can't provide a solution because you haven't provided enough information. What do you mean "waiting for input all the time"? Input from where? If the input produces a continuous stream of data do you really want the body of your
whileloop running as fast as it can execute? Having said that you probably want to replace theinput()with a simplesys.stdin.readline()to avoid the impliciteval().