Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8555171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:03:46+00:00 2026-06-11T15:03:46+00:00

I have a python script which must call a perl script to get data

  • 0

I have a python script which must call a perl script to get data from a remote server.
The perl script has to stay perl, it’s third party and I don’t have any options there.
I’m trying to remove all the obsolete and deprecated stuff that the previous developer stuck all around the code, so I’d like to replace the commands.getstatusoutput call with a subprocess call, but somehow I can’t seem to get it to work…

Up until now, the script was called via commands.getstatusoutput(string) where string is the full system call to the perl script, as in ‘/usr/bin/perl /path/to/my/perl/script.pl < /path/to/my/input’.

I create a list of arguments (args = [‘/usr/bin/perl’, ‘/path/to/my/perl/script.pl’, ‘<‘, ‘/path/to/my/input’]) and I pass it to subprocess.call:

args = ['/usr/bin/perl', '/path/to/my/perl/script.pl', '<', '/path/to/my/input']
strOut = subprocess.call(args)
print strOut

Unfortunately, this fails with the error :

port absent at /path/to/my/perl/script.pl line 9.

The perl script is :

#!/usr/bin/perl
use IO::Handle;
use strict;
use Socket;
my ($remote, $port, $iaddr, $paddr, $proto, $ligne);
$remote = shift || 'my.provider.com';
$port   = shift || 9000;
if ($port =~ /\D/) { $port = getservbyname ($port, 'tcp'); }
die "port absent" unless $port;

Despite reading other similar threads here (Call perl script from python, How to call a perl script from python?, How can I get the results of a Perl script in Python script?, Python getstatusoutput replacement not returning full output etc) and elsewhere, I get the feeling I am missing something obvious but I can’t work out what.

Any ideas?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T15:03:48+00:00Added an answer on June 11, 2026 at 3:03 pm

    redirection < is a shell feature. If you want to use it, you’ll need to pass a string to subprocess.call and use shell = True. e.g.:

    args = ['/usr/bin/perl', '/path/to/my/perl/script.pl', '<', '/path/to/my/input']
    strOut = subprocess.call(' '.join(args), shell = True)
    

    Alternatively, you can do:

    args = ['/usr/bin/perl', '/path/to/my/perl/script.pl']
    with open('path/to/my/input') as input_file:
        strOut = subprocess.call(args, stdin = input_file) 
    

    Finally, strOut will hold the return code from your perl program — this seems like a funny name for it. If you want to get at the output stream (stdout) from your perl program, you’ll probably want to use subprocess.Popen in conjunction with stdout=subprocess.PIPE and communicate.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Python script which retrieves data from an API in JSON format (at
I have python script which downloads N number of images from website. I run
I have a python script which outputs lots of data, sample is as below.
i have a python script which keeps crashing on: subprocess.call([pdftotext, pdf_filename]) the error being:
I have a list which I have obtained from a python script. the content
Requirements : I have a Python project which parses data feeds from multiple sources
I have a XML document data.xml: I need to write python script which can
I have a python script which is constantly polling data. The script is constantly
I have a python script which is querying a MySQL server on a shared
I have a small python script which draws some turtle graphics. When my script

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.