Calls to external program from Python

Calls to external program from Python


Python, often used to glue together different components of an application, provides various mechanisms to call external programs. By supporting these calls the analyzer can provide the linkage between different technology layers.

Supported API methods Link Type Caller Callee
os.system, os.popen,, subprocess.check_call,, subprocess.Popen callLink Python callable artifact Python Call to Java Program, Python Call to Generic Program

Technologies currently handled by the Python analyzer

The Python analyzer currently supports calls to the following technologies

  • Cobol
  • Java: classes and .jar
  • Python
  • Shell

The Java technology is specific and has its own object because links are made using the fullname of the class, package and class name.

Furthermore, the link is not made to the class object but directly to its main method. Indeed, Java program can only be called if they contain a main method.

CAST Enlighten screenshots

When a call to an external program is analyzed by the Python analyzer, the following transactions can be found at the end of analysis:

Example of call to an external program

import subprocess
from subprocess import Popen'/bin/java com.cast.Classe')
cmd = './'
popen = Popen(cmd)

CAST Enlighten screenshot of call to an external program

Python code can also call a different Python program via the python (or jython) executable. Then the analyzer will create, as shown before, “Python Call to Generic Program” objects and they will be linked to the corresponding “Python Main” objects during application level analysis via web service linker extension. For example will invoke the script in the code below


import subprocess
from subprocess import Popen

cmd = 'python'
popen = Popen(cmd)

where the target code contains a code block in the top-level script environment (signaled by the “if __name__ …” structure).


def run():

if __name__=="__main__":

so as a results we would have