LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   perl script call python -linux (http://www.linuxquestions.org/questions/programming-9/perl-script-call-python-linux-551063/)

cdd 05-03-2007 03:14 PM

perl script call python -linux
 
Hi,
I have a perl script that is running in windows environment. This is calling python BodyTextExtractor.
My problem is: I have to move the script to run on linux and I have to change the following part of the script and I don't know how. Please help me!

use Win32::Job;
...............................................

$job = Win32::Job->new;

open(FILE_tmp2, ">$PName");
$job->spawn("C:\\Python24\\python.exe", "python BodyTextExtractor.py $PName.txt",
{
stdout => FILE_tmp2,
});
$status = $job->run(60);
close FILE_tmp2;


Thanks a lot!

ghostdog74 05-03-2007 06:32 PM

Quote:

Originally Posted by cdd
Hi,
I have a perl script that is running in windows environment. This is calling python BodyTextExtractor.
My problem is: I have to move the script to run on linux and I have to change the following part of the script and I don't know how. Please help me!

use Win32::Job;
...............................................

$job = Win32::Job->new;

open(FILE_tmp2, ">$PName");
$job->spawn("C:\\Python24\\python.exe", "python BodyTextExtractor.py $PName.txt",
{
stdout => FILE_tmp2,
});
$status = $job->run(60);
close FILE_tmp2;


Thanks a lot!

if this is just the script you have and no others, why not try to run it in Python.
Just call the BodyText python script using the python interpreter.
#python BodyTextExtractor.py filename

Valdis Grinbergs 05-03-2007 10:01 PM

If you really want to call a python script from perl, you could use something like this:

open(STDOUT, ">$PName") || die "Can't redirect stdout";
$status = system("python BodyTextExtractor.py $PName.txt");

Alternately, if you need better control on this subprocess, you might want to look at either IPC::Run3 or IPC::Run (see http://search.cpan.org/~rjbs/IPC-Run...b/IPC/Run3.pm).

Good luck!

cdd 05-04-2007 03:08 PM

Thank you for the answers.
You really help me a lot!

Thanks again,
cdd


All times are GMT -5. The time now is 10:12 PM.