简体   繁体   中英

How to open a window from the command line within a Python script?

I am working on a python script to analyze astronomy images and I am trying to open a DS9 window within a python script (DS9 is a utility that allows images to be interactively viewed and analyzed). Usually I would open DS9 by going into the Linux terminal and typing:

>ds9 &

and then it would pop up in another window.

I tried to mimic this in my python script by writing the following line:

os.system('ds9 &')

When I would run the script the DS9 window would pop up but the rest of the script would not run until I closed the DS9 window. This gave me errors because the tasks that followed needed a DS9 window to be opened.

I am wondering if there is a way to open a window from within a python scripts and still have the rest of the script continue running.

Perhaps:

os.system('ds9 &')

isn't the right approach?

You can use subprocess module.
subprocess is a newer way to spawn processes rather than using os.spawn*() or os.system() .

In your case:

import subprocess
subprocess.Popen(["ds9"])

This should run ds9 in background.

See the documentation here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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