简体   繁体   English

Python 自动开启申请

[英]Python automate open application

Please give me idea regarding how to tackle this problem.请给我关于如何解决这个问题的想法。 I am not able to find any resource regarding this.我找不到与此相关的任何资源。 Your help will be immensely valuable.您的帮助将非常宝贵。 So we have one limited license software.所以我们有一个有限许可软件。 And want to reiterate the python invoking the application.并想重申调用应用程序的 python。 If the application gives the error that licence is not available it should close the application and wait for sometime say 1 min and again invoke the process, it should do so endlessly until a licence is available and the application is finally open.如果应用程序给出许可证不可用的错误,它应该关闭应用程序并等待一段时间,比如 1 分钟,然后再次调用该过程,它应该无休止地这样做,直到许可证可用并且应用程序最终打开。 I am able to open the application using我可以使用打开应用程序

Import os
os.startfile('application executable')

After this I want the application to know if there is an error window popping, it should close the window and wait for sometime and again open the application在此之后我想让应用程序知道是否弹出错误 window,它应该关闭 window 并等待一段时间再打开应用程序

os.startfile returns as soon as the associated application is launch so use Popen instead. os.startfile 会在关联的应用程序启动后立即返回,因此请改用 Popen。

As you are using windows use these steps.当您使用 windows 时,请使用这些步骤。

To Open a Shortcut using Popen on Windows first install pywin32要在 Windows 上使用 Popen 打开快捷方式,请先安装 pywin32

Step one:第一步:

python -m pip install pywin32

Step two:第二步:

Navigate to your python Scrips folder something like C:\Users\Name\AppData\Local\Programs\Python\Python38-32\Scripts then type the command.导航到 python Scrips 文件夹,例如 C:\Users\Name\AppData\Local\Programs\Python\Python38-32\Scripts,然后键入命令。

pywin32_postinstall.py -install

Then the code to use Popen is.然后是使用 Popen 的代码。

import subprocess
import win32com.client, win32api

shell = win32com.client.Dispatch("WScript.Shell")
shortcut = shell.CreateShortCut(r'path to shortcut')
long_path = shortcut.Targetpath
p = subprocess.Popen(long_path)
p.wait()

Welcome to 2022!欢迎来到 2022!

You can simply make use of PYPI module AppOpener .您可以简单地使用 PYPI 模块AppOpener

# pip install AppOpener
from AppOpener import run
run("whatsapp") #Opens whatsapp if installed
run("whatsapp, telegram") # Opens whatsapp & telegram

Visit AppOpener's documentation here .在此处访问 AppOpener 的文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM