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!

4
  • What exactly is the program "idl" you're trying to execute? Commented Jun 29, 2016 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. Commented Jun 29, 2016 at 13:54
  • There are many implementations of IDL. Can you provide a link to the version you're using? Commented Jun 29, 2016 at 14:05
  • I think I have a solution now, but thatnks for the though anyway. It was using IDL 8.2 Commented Jun 29, 2016 at 14:37

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.