python - 用于打开 ubuntu 应用程序的 Python 脚本
问题描述
如何编写python脚本在ubuntu中打开应用程序
我尝试了 os 模块,但它没有用
解决方案
运行系统程序的两种常用方法是 os.system() 和 subprocess 模块。
os.system
获取类似命令的终端作为参数,因此您可以像在终端中一样启动后台进程
>>> import os
>>> os.system("nautilus /tmp &")
0
如果要获取流程输出;
>>> import subprocess
>>> subprocess.check_output(
... "ls non_existent_file; exit 0",
... stderr=subprocess.STDOUT,
... shell=True)
'ls: non_existent_file: No such file or directory\n'
推荐阅读
- docker - 将 docker 容器托管到本地网络
- wordpress - 无法在 Wordpress 中更改网站语言
- javascript - 如何阻止我的“轮盘赌风格”号码选择器滞后?
- reactjs - 当我转到“联系人路径”时,我希望 App 中的组件不出现
- python - Django 表单提交重定向到错误的 url
- angular - 尝试在Angular Typescript中填充以特定数字开头的数组
- amazon-web-services - 由 CI/CD 发布时 AWS ECS 计划任务未运行
- python - 为什么 AWS Lambda 会通过 CloudWatch 事件多次运行?
- java - 我应该如何重构现有代码来处理新案例?
- python - 如何创建直接在任何用户中运行的脚本?