[英]How to change the code so that after the reboot it works and is visible in the terminal?
below is my code.下面是我的代码。 I use a crontab for autostart, but everything works not as I would like.我使用 crontab 进行自动启动,但一切都不像我想要的那样工作。 The goal was that after starting raspberry, the terminal would open, and the program would run in it so that when you typed "bye" the program ended (which I already have).目标是在启动 raspberry 后,终端会打开,程序会在其中运行,这样当你输入“再见”时,程序就会结束(我已经有了)。
import os
import sys
import subprocess
if os.geteuid() == 0:
while True:
file = open("here is my file path")
print(file.read())
my_input = input("Do you want to close this program? Type bye if yes")
if my_input== 'bye':
print("bye")
break
else:
subprocess.call(['sudo', 'python3'] + sys.argv)
How to change the code so that after the reboot it works and is visible in the terminal?如何更改代码以便在重新启动后它可以工作并且在终端中可见?
using a daemon service would probably be more appropriate than "cron".使用守护程序服务可能比“cron”更合适。 but it doesn't matter because your script checks if the user is root ( geteuid() ) and tries to do a sudo if this is not the case, so the sudo will only fail because the script doesn't have the rights.但这没关系,因为您的脚本会检查用户是否为 root ( geteuid() ),如果不是这种情况,则会尝试执行 sudo,因此 sudo 只会失败,因为脚本没有权限。 If your script has a standard user uid, and it is executed by root, then you must make a call to seteuid(0), to set the rights to root如果你的脚本有一个标准的用户 uid,并且它是由 root 执行的,那么你必须调用 seteuid(0) 来设置 root 的权限
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.