0

I have a number of different codes which all take a text file with data as input and write to a different one as output. Three of these codes are written in Python 2.7, but one is written in IDL. My goal is to create one "master" python program which can run all of these codes, by typing "python master.py". However, because of the limitations of my system, I am unable to use the 'pyIDL' or 'pyIDLy' modules referred to in this question. Not sure if it matters, but this is using a linux command prompt.

Currently my 'master.py' code looks like this:

import os
os.system("python pycode_1.py")

os.system("idl")
os.system(".com idlcode.pro")
os.system(".r idlcode,"imputfile.dat"")
os.system("exit")

os.system("python pycode_2.py")
os.system("python pycode_3.py")

This code runs the first python code and enters IDL fine. However, it does not enter the later comands into IDL. This means that the IDL command prompt comes up, but I cannot run the IDL code that follows.

I would be very appreciative about any advice to solve this issue. Thanks in advance!

Community
  • 1
  • 1
TheBoro
  • 223
  • 1
  • 2
  • 11
  • What exactly is the program "idl" you're trying to execute? – Aya Jun 29 '16 at 13:43
  • idl is a programming language. So the command 'idl' starts up the idl command line prompt, analogous to typing 'python'. Then the following commands should compile and run the script. – TheBoro Jun 29 '16 at 13:54
  • There are many implementations of IDL. Can you provide a link to the version you're using? – Aya Jun 29 '16 at 14:05
  • I think I have a solution now, but thatnks for the though anyway. It was using IDL 8.2 – TheBoro Jun 29 '16 at 14:37

2 Answers2

2

If you have IDL 8.5 or later, it ships with the IDL-Python bridge built in. Then your code would look something like:

from idlpy import *
IDL.idlcode()

Hope this helps.

Chris Torrence
  • 452
  • 3
  • 11
0

So I have worked out a solution that seems to work well for this problem. The issue above was the use of the os.system function to do things it couldn't. My new codde is:

import os
import subprocess

os.system("python python_code1.py")

p=subprocess.Popen("idl", stdin=subprocess.PIPE, stdout=subprocess.PIPE)
p.stdin.write(".com idlcode.pro\n")
p.stdin.write("idlcode\n")
p.stdin.write("exit")
p.wait()
os.system("python python_code2.py")
os.system("python python_code3.py")
TheBoro
  • 223
  • 1
  • 2
  • 11