Home > Back-end >  How can I make applications opened by subprocess.Popen() stay open after my script exits?
How can I make applications opened by subprocess.Popen() stay open after my script exits?

Time:11-05

I want to launch Excel using subprocess.Popen() but my script doesn't work as expected.

The following simple script doesn't work in the way I want it to work. It looks like Excel is terminated immediately when the script ends. What do I need to do to keep it open?

import subprocess
subprocess.Popen(r'C:\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.EXE')

If I enter the same codes into the interactive shell, it works as expected and Excel stays open.

Any help would be greatly appreciated!

CodePudding user response:

you can use the following

import os
os.system("start excel.exe")

CodePudding user response:

import subprocess

subprocess.run(r'C:\Program Files\Microsoft Office\root\Office16\EXCEL.EXE')

Stays Open Until Exit, Then you get this next line...

CompletedProcess(args='C:\Program Files\Microsoft Office\root\Office16\EXCEL.EXE', returncode=0)

If you want to do multiple, then multithreading is your answer.

  • Related