DAOPHOT is a FORTRAN-written software for performing astronomy tasks in images. A typical flow of its usage is:
- Open a terminal (gnome-terminal in my case) and run
./daophot
. I'm now within DAOPHOT's shell. - Prompts the user for a command, let's say
ATTACH
to input an image file. DAOPHOT runs and prompts the user again for more commands. - User gives another command, let's say
PHOTOMETRY
. DAOPHOT runs and prompts the user again.
For every command the user gives, DAOPHOT runs and prompts again and again until exit
is typed. For my case, I have three specific commands that will run one after another, without variation (ATTACH
, PHOTOMETRY
and PSF
, with the latter maybe run more than once).
Right now I'm simply trying to ATTACH
a file. What I have tried:
Using subprocess
, as seen/asked here and here:
import subprocess
p = subprocess.Popen(["gnome-terminal","--disable-factory","--","./daophot"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p.stdin.write(input("ATTACH file.fits"))
For this case, DAOPHOT's shell opens but the ATTACH command is not executed. I close the shell and the string "ATTACH file.fits" appears in the IPython terminal, ending the subprocess. I've tried also to use p.communicate(input=input("ATTACH file.fits"))
, but got the same result.
Using pexpect
, as seen/asked here and here:
import pexpect
p = pexpect.spawn("gnome-terminal --disable factory -- ./daophot")
p.expect(pexpect.EOF)
p.sendline("ATTACH file.fits")
In this case, DAOPHOT's shell opens but the ATTACH command is not accounted for as an input.
Finally, a DAOPHOT wrapper already exists, but the idea is to have this automatically and interactive Python version in our lab, so that we can change later if needed.
From what I understand in terms of pipelines, ./daophot
is a subsubprocess runnning inside gnome-terminal
, so when I use e.g. p.stdin.write(input("ATTACH file.fits")
I am actually inputing this command into gnome-terminal
, and not into ./daophot
.
Any help is much appreciated.