I need to call "/usr/bin/pdf2txt.py" with few arguments from my Perl script. How should i do this ?
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.
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.
my $output = `/usr/bin/pdf2txt.py arg1 arg2`;
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With