Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call a python script from Perl?

Tags:

python

perl

I need to call "/usr/bin/pdf2txt.py" with few arguments from my Perl script. How should i do this ?

like image 941
Mandar Pande Avatar asked Jun 14 '11 07:06

Mandar Pande


People also ask

How do you call a Perl script in Python?

Open your Python code in your Python editor of choice. Go to the line in the code where you want to run your Perl script. Type "pyth. RunPerl.

Can we convert Perl script to Python?

Here are the simple steps to convert PERL scripts to Python. Remove all ';' at the end of the line. Remove all curly brackets and adjust indentation. Convert variables names from $x, %x or @x to x.


2 Answers

my $output = `/usr/bin/pdf2txt.py arg1 arg2`;
like image 41
Blagovest Buyukliev Avatar answered Sep 19 '22 17:09

Blagovest Buyukliev


If you need to capture STDOUT:

my $ret = `/usr/bin/pdf2txt.py arg1 arg2`;

You can easily capture STDERR redirecting it to STDOUT:

my $ret = `/usr/bin/pdf2txt.py arg1 arg2 2>&1`;

If you need to capture the exit status, then you can use:

my $ret = system("/usr/bin/pdf2txt.py arg1 arg2");

Take in mind that both `` and system() block until the program finishes execution.

If you don't want to wait, or you need to capture both STDOUT/STDERR and exit status, then you should use IPC::Open3.

like image 153
Francisco R Avatar answered Sep 16 '22 17:09

Francisco R