How To Integrate Perl, Ruby, and Python Programs

Problem scenario
You want a Perl program to call a Python program to call a Ruby program to call another Python program.  You are using Linux as the OS.

Solution
Here is a one-line Perl program (course.pl) that calls a Python program:

system( "python /home/ec2-user/cont.py");

Here is a two-line Python program named cont.py.  It invokes a Ruby program.

import subprocess
subprocess.call(['ruby /home/ec2-user/integration.rb'], shell=True)

Here is a one-line Ruby script file named integration.rb (that calls a Python script). 

exec( "python /home/ec2-user/new.py" )

Here is a one-line Python program that prints a basic message, name it "new.py":

print "This final Python script worked!!!"

If each of the above four programs (course.pl, cont.py, integration.rb, new.py) are all in the /home/ec2-user/ directory, just run the Python program like this:  perl course.pl

It will print "This final Python script worked!!!"  This demonstrates integration of three languages with four files and five lines of code. 

Leave a comment

Your email address will not be published.