473,396 Members | 1,780 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

perl script call python -linux

2
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!

Expand|Select|Wrap|Line Numbers
  1. use Win32::Job;
  2. ...............................................
  3.  
  4. $job = Win32::Job->new;
  5.  
  6. open(FILE_tmp2, ">$PName");
  7. $job->spawn("C:\\Python24\\python.exe", "python BodyTextExtractor.py $PName.txt", {
  8.     stdout => FILE_tmp2,
  9. });
  10. $status = $job->run(60);
  11. close FILE_tmp2;
  12.  
Thanks a lot!
May 3 '07 #1
3 10642
prn
254 Expert 100+
There's always more than one way to do it :) but it looks to me like this does approximately the same thing yours does:

Expand|Select|Wrap|Line Numbers
  1. $status = system "/usr/bin/python BodyTextExtractor.py $PName.txt >$PName";
  2.  
Of course, I know nothing about BodyTextExtractor.py and what it wants for input, what it would do with output, etc. I'm also not sure what you want to do with the $status or what values you're checking. See the perldocs for the System function since that may be different from the Win32::Job status return values. The reference also gives some examples of how you might check those values.

In my own programs, I also normally extract system-dependent commands like "C:\\Python24\\python.exe" or "/usr/bin/python" into variables (essentially constants) that I define near the beginning of the perl program. It makes life easier when you have to do something like move the script to a different platform. You might want to do that while you're porting. So, e.g.:

Expand|Select|Wrap|Line Numbers
  1. $Python = '/usr/bin/python';
  2. $Extractor = 'BodyTextExtractor.py';
  3. ....
  4. $status = system "$Python $Extractor $PName.txt >$PName";
  5.  
Of course, I also don't know what you're planning to do with the output, which it looks like you're sending to a temporary file. If you're planning to process that output futher in your own program, you might be better off using a construct like:

Expand|Select|Wrap|Line Numbers
  1. $command = "$Python $Extractor $PName.txt";
  2. open IN, "$command |"
  3.     or die "Could not execute \"$command\": $!\n";
  4. @lines = <IN>;
  5. close IN;
  6.  
Note the "pipe" symbol at the end of the command. This pipes the output of BodyTextExtractor.py directly into your (calling) perl program and you can then just collect them into an array such as @lines. You may find this a useful idiom. Or, alternatively, it may not be what you want here.

As usual, the answer is "it depends."

Best Regards,
Paul
May 4 '07 #2
KevinADC
4,059 Expert 2GB
look into the perl functions alarm() or using the four argument version of select().

alarm
select
May 4 '07 #3
cdd
2
Thank you for the answers.
You really help me a lot!

Thanks again,
cdd
May 4 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: sam | last post by:
I have a function writen in Perl that takes a name-value list (array) as argument and returns a name-value list (array). My question is: How to call this function from PHP and get the returned...
0
by: SS | last post by:
I am trying to execute some python commands within a perl script and running into problems. The following works: python -c "import mypkg;do this; do that" however when I try to do something like...
13
by: Wayne Folta | last post by:
I've been a long-time Perl programmer, though I've not used a boatload of packages nor much of the tacky OO. A couple of years ago, I decided to look into Python and Ruby. Python looked OK, but...
5
by: Premshree Pillai | last post by:
Hello, I recently wrote a Perl version of pyAlbum.py -- a Python script to create an image album from a given directory -- plAlbum.pl . It made me realize how easy-to-use Python is. ...
52
by: Olivier Scalbert | last post by:
Hello , What is the python way of doing this : perl -pi -e 's/string1/string2/' file ? Thanks Olivier
1
by: Marc H. | last post by:
Hello, I recently converted one of my perl scripts to python. What the script does is simply search a lot of big mail files (~40MB) to retrieve specific emails. I simply converted the script...
3
by: dpackwood | last post by:
Hello, I have two different scripts that do pretty much the same thing. The main perl script is on Windows. It runs and in the middle of it, it then calls out another perl script that then...
3
by: David Bear | last post by:
I have a hash function written by another organization that I need to use. It is implemented in perl. I've been attempting to decode what they are doing in their hash function and it is taking way...
4
by: pmcgover | last post by:
I enjoyed Paul Barry's September article in Linux Journal entitled, "Web Reporting with MySQL, CSS and Perl". It provides a simple, elegant way to use HTML to display database content without any...
5
by: Karyn Williams | last post by:
I am new to Pyton. I am trying to modify and understand a script someone else wrote. I am trying to make sense of the following code snippet. I know line 7 would be best coded with regex. I first...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.