登录时在终端中运行python脚本 [英] Run python script in terminal at login
本文介绍了登录时在终端中运行python脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了一个python脚本,其中包含一个无限循环菜单.我的目标是在用户登录时在终端中启动脚本并开始与其进行交互.我已经创建了launcher.sh文件,它将在启动时执行并将其注册到crontab中.但是,系统重新启动时会出现以下错误:
I have written a python script which contains a menu in an infinite loop. My goal is start the script in terminal when a user logs in and start interacting with it. I have created a launcher.sh file which will execute on startup and registered it in crontab. However, when system reboots it gives following error:
1: START
2: POWEROFF
Please make a choice: Traceback (most recent call last):
File "menu.py", line 27, in <module>
main()
File "menu.py", line 16, in main
choice = input ("Please make a choice: ")
EOFError: EOF when reading a line
这是我的剧本:
#!/usr/bin/python3
def main():
while True:
print("1: START")
print("2: POWEROFF")
choice = input ("Please make a choice: ")
print(choice)
... other operations
这是我的launcher.sh文件:
Here is my launcher.sh file:
#!/bin/sh
# launcher.sh
cd /home/rao/Desktop/project
sudo python3 menu.py
cd /
和crontab行:
@reboot sh /home/rao/Desktop/project/launcher.sh >> /home/rao/Desktop/project/logs/status.log 2>&1
我要去哪里错了?
推荐答案
当我在启动应用程序
x-terminal-emulator -e "python3 /path-to-script/menu.py"
这篇关于登录时在终端中运行python脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文