I want to pipe a file path from Python to a Perl script. Although I'm familiar with Python and Bash I don't known anything about Perl.
I have the following (example) files:
return.py
print( 'data/test.txt' )
uniprot.pl
use strict;
use warnings;
use LWP::UserAgent;
my $list = $ARGV[0]; # File containg list of UniProt identifiers.
my $base = 'http://www.uniprot.org';
my $tool = 'uploadlists';
my $contact = ''; # Please set your email address here to help us debug in case of problems.
my $agent = LWP::UserAgent->new(agent => "libwww-perl $contact");
push @{$agent->requests_redirectable}, 'POST';
my $response = $agent->post("$base/$tool/",
[ 'file' => [$list],
'format' => 'fasta',
'from' => 'ACC+ID',
'to' => 'ACC',
],
'Content_Type' => 'form-data');
while (my $wait = $response->header('Retry-After')) {
print STDERR "Waiting ($wait)...\n";
sleep $wait;
$response = $agent->get($response->base);
}
$response->is_success ?
print $response->content :
die 'Failed, got ' . $response->status_line .
' for ' . $response->request->uri . "\n";
When I call the perl file from the shell like: perl uniprot.pl data/test.txt it works fine.
I tried different approaches to pipe the python print to this call, but apparently the wrong ones:
1.
python3 return.py | perl uniprot.pl
This will give: Failed, got 500 Internal Server Error for http://www.uniprot.org/uploadlists/. However as I know the code works (as said above) this has to be caused by wrong piping.
2
python3 return.py | perl uniprot.pl -
This will give: Can't open file -: No such file or directory at /usr/share/perl5/LWP/UserAgent.pm line 476. So it seems that the string is passed to the perl file, however perl is looking in a complete different directory.
3
I changed this line: my $list = $ARGV[0]; --to--> my $list = <STDIN>; and then again calling both the above commands (thus 1 and 2). Both give: Can't open file data/test.txt
: No such file or directory at /usr/share/perl5/LWP/UserAgent.pm line 476.
Question
How can I pass the string from return.py to uniprot.pl?