python3 Examples of opening and closing external programs

  • 2021-01-22 05:16:33
  • OfStack

This is as follows:


import os
import time
import subprocess
 
subprocess.Popen(r'cmd')
print(' Open the success ')
time.sleep(5)
print(' rest 5s')
os.system(r'taskkill /F /IM  The process of ')
print(' Close the success ')

Note:

subprocess.getoutput(cmd) and os.system(cmd) can also open programs

But it's not asynchronous, the external program doesn't close, the program doesn't go down.


Related articles: