【发布时间】:2017-08-22 09:25:12
【问题描述】:
我的 python 脚本的输出存在问题,该脚本在树莓派启动后自动运行并将其输出写入我使用 crontab 创建的 output.txt 文件中。我的代码是这样的:
while True:
f=open('test.txt','w+')
d_date = datetime.datetime.now()
reg_format_date = d_date.strftime("%Y/%m/%d %H:%M:%S")
print(reg_format_date)
f.write(reg_format_date)
for x in range (27,14,-1):
key_in=GPIO.input(x)
if key_in==0:
y='1'
print(y)
f.write(y)
else:
y='0'
print(y)
f.write(y)
f.close()
在 crontab 我有这样写
@reboot python /home/pi/test.py >> /home/pi/output.txt&
我的脚本的输出是:
2017/08/13 01:49:12
0
1
1
1
1
0
0
0
0
0
0
0
0
我想要的输出格式:2017/08/12 01:33:28 0111100000000
【问题讨论】:
标签: python cron raspberry-pi output autorun