Python automate open application

909 Views Asked by At

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. 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. 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

1

There are 1 best solutions below

0
recurseuntilfor On

os.startfile returns as soon as the associated application is launch so use Popen instead.

As you are using windows use these steps.

To Open a Shortcut using Popen on Windows first install 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.

pywin32_postinstall.py -install

Then the code to use Popen is.

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()