prema
prema

Reputation:

How can I get the results of a Perl script in Python script?

I have one script in Perl and the other in Python. I need to get the results of Perl in Python and then give the final report. The results from Perl can be scalar variable, hash variable, or an array.

Please let me know as soon as possible regarding this.

Upvotes: 1

Views: 1579

Answers (3)

bedwyr
bedwyr

Reputation: 5874

Use the subprocess module to run your Perl script to capture its output:

You can format the output however you choose in either script, and use Python to print the final report. For example: your Perl script can output XML which can be parsed by the Python script and then printed using a different format.

Upvotes: 6

Chas. Owens
Chas. Owens

Reputation: 64929

Take a look at PyYAML in Python and YAML in Perl.

Upvotes: 3

Sean Turner
Sean Turner

Reputation: 1178

You could serialize the results to some sort of a string format, print this to standard output in the Perl script. Then, from python call the perl script and redirect the results of stdout to a variable in python.

Upvotes: 2

Related Questions