Link to home
Create AccountLog in
Avatar of ambuli
ambuliFlag for United States of America

asked on

Perl: executing a python script from perl program

Hi Experts,

I need to somehow use a python script in a perl program.  I don't know python, so I cannot write the entire thing in python.  But, I want to use a python script that was written by someone else.

The python script accepts one input.

How can I do it?
ASKER CERTIFIED SOLUTION
Avatar of brutaldev
brutaldev
Flag of South Africa image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Or, similar to brutaldev's suggestion, call it with backticks to read the output of the Python script.

my $s = `myscript.py foo bar`;
print "Script returned $s";

Avatar of ambuli

ASKER

Thank you very much.  One small question.  The system call does not take $inputfile as an argument to the script. Also, I had to remove the " " around $Python $PyScript.
What could be wrong.

...
foreach $inputfile (@inputfiles)
{
    chomp($inputfile);
    system($Python $PyScript, $inputfile ) == 0 or die "Could not execute script.";
}
Avatar of ambuli

ASKER

If the argument is filenameone, it should be passed as it is. Not "filenameone".
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of ambuli

ASKER

Thank you.