469,293 Members | 1,319 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,293 developers. It's quick & easy.

perl script call python -linux

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. ...............................................
  4. $job = Win32::Job->new;
  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;
Thanks a lot!
May 3 '07 #1
3 10299
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";
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";
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;
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,
May 4 '07 #2
4,059 Expert 2GB
look into the perl functions alarm() or using the four argument version of select().

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

Thanks again,
May 4 '07 #4

Post your reply

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

Similar topics

1 post views Thread by sam | last post: by
reply views Thread by SS | last post: by
13 posts views Thread by Wayne Folta | last post: by
5 posts views Thread by Premshree Pillai | last post: by
52 posts views Thread by Olivier Scalbert | last post: by
3 posts views Thread by David Bear | last post: by
4 posts views Thread by pmcgover | last post: by
5 posts views Thread by Karyn Williams | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.