【问题标题】:How to lunch an applications on linux using python script? [duplicate]如何使用 python 脚本在 Linux 上为应用程序提供午餐? [复制]
【发布时间】:2017-08-20 10:57:05
【问题描述】:

我必须定期在 Linux 机器上使用多个类似的应用程序,所以我想编写一个脚本来打开它们而不会失败。

请你帮我写一个脚本来一次打开多个应用程序。

示例:Firefox 和 Libre office cal

您能否建议可以打开这些应用程序(Firefox 和 Libre office cal)的脚本,以便我可以构建自定义脚本来打开多个应用程序。

脚本:

import os
import browser
from threading import Thread

def app1(my_app_name):

  os.system(my_app_name)


def main():
 t1 = Thread(target=app1, args=(('firefox',)) )
 #t2 = Thread(target=app1 , args=(('libreoffice',)) )
 t1.start()
 #t2.start()


if __name__ == '__main__':
 main()

【问题讨论】:

  • 你可以使用线程和(os)模块

标签: python linux python-3.x


【解决方案1】:

也许有用:

import os
from threading import Thread

def app1(my_app_name):

  os.system(my_app_name)


def main():
 t1 = Thread(target=app1, args=(('firefox',)) )
 t2 = Thread(target=app1 , args=(('libreoffice',)) )
 t1.start()
 t2.start()


if __name__ == '__main__':
 main()

我使用 (os) 来执行 linux 命令 shell(你也可以将它用于 windows) 和 Thread 用于并行运行程序

【讨论】:

  • 能否以app1=Firefox & app2= libre office cal 为例并编写脚本?
  • 我现在检查一下
  • 它对我有用,只需使用 firefox 而不是 'ls' 或任何程序或 linux 命令
  • 我的代码有什么问题?
  • @MaheshAknur 有什么问题吗?如果没有,请接受并在我的解决方案中添加标记
猜你喜欢
  • 2017-09-29
  • 2013-09-26
  • 1970-01-01
  • 1970-01-01
  • 2021-08-12
  • 2015-04-04
  • 2014-05-14
  • 2019-05-17
  • 2014-09-02
相关资源
最近更新 更多