要求:(1)进入桌面后,启动terminal,运行python程序;(2)传递参数执行
一、自动执行
1.1、在开始中查找

1.2、选择启动应用程序

1. 3、输入相应的命令

1.4、如果启动terminal,则格式如下,先后启动2个程序看看
(1)
gnome-terminal -- python3 /home/chen/chentest/chentest1.py
(2)
gnome-terminal -- python3 /home/chen/chentest/chentest2.py
1.5、对应的两个测试程序
(1)chentest1.py
#引入opencv模块
import cv2 as cv
#查看opencv的版本
print(cv.__version__)
print("chen1kaishi")
while True:
print("chen11")
cv.waitKey(1000)
(2)chentest2.py
#引入opencv模块
import cv2 as cv
#查看opencv的版本
print(cv.__version__)
print("chen2kaishi")
while True:
print("chen22")
cv.waitKey(1000)
二、传递参数执行
1、传递参数的例子
chentestparam.py
import argparse
import time
def chen_param_test():
parser = argparse.ArgumentParser()
parser.add_argument("--chenip", default='192.168.1.110')
parser.add_argument("--chenid", default = 1)
args = parser.parse_args()
print(args.chenip)
print(args.chenid)
while True:
print("chen ip: " + str(args.chenip) + " id: "+ str(args.chenid))
time.sleep(1)
# pass
if __name__ == '__main__':
chen_param_test()
#python chentestparam.py --chenip='192.168.1.199' --chenid=3
#python chentestparam.py --chenid=6 --chenip='192.168.1.199'
2、自动启动terminal对应的命令,启动多个试试看
(1)
gnome-terminal -- python3 /home/chen/chentest/chentestparam.py --chenid=6 --chenip='192.168.1.199'
(2)
gnome-terminal -- python3 /home/chen/chentest/chentestparam.py --chenid=5 --chenip='192.168.1.200'
本文介绍了如何在Linux环境下通过gnome-terminal自动启动并运行Python程序,包括无参数和带参数的执行方式。示例中展示了两个使用opencv的测试脚本chentest1.py和chentest2.py,以及一个接收命令行参数的脚本chentestparam.py,演示了如何传递参数如IP地址和ID来定制程序行为。
1516

被折叠的 条评论
为什么被折叠?



