0

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

Manualmsdos
  • 1,505
  • 3
  • 11
  • 22
  • what OS are you using? – fixmycode Nov 11 '19 at 06:30
  • startfile() returns as soon as the associated application is launched. There is no option to wait for the application to close, and no way to retrieve the application’s exit status. Popen allows you to wait. – recurseuntilfor Nov 11 '19 at 06:53
  • Windows.. also i am trying to open an application from the shortcut of the application. How to open a shortcut using popen – user11952346 Nov 11 '19 at 06:56

1 Answers1

0

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()
recurseuntilfor
  • 2,293
  • 1
  • 12
  • 17