Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

replace use HTTP::Lite to run a perl file that was on another server

by bNathan (Novice)
on Feb 19, 2017 at 17:54 UTC ( [id://1182307]=perlquestion: print w/replies, xml ) Need Help??

bNathan has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

I have a perl script that used http:Lite to run "copyorders_multiple.pl" on a different server.

I have condensed servers so that the perl script "copyorders_multiple.pl" is now in the same cgi-bin directorty as the perl script that is calling for that script.

Can anyone here help me rewrite the command to not use http::lite

use HTTP::Lite; $http = new HTTP::Lite; $req = $http->request("copyorders_multiple.pl?refID=".&trim($license)) + or die "Unable to get document: $!"; $data = $http->body(); if (length(&trim($data)) > 0)

Replies are listed 'Best First'.
Re: replace use HTTP::Lite to run a perl file that was on another server
by huck (Prior) on Feb 19, 2017 at 18:49 UTC

    It is not as simple as you expect. You may wish to see this node Re: Testing out a CGI script using the command line. But that still leaves you with a problem that the data section is not stripped from the whole response. Using get_response from that node and untested you might try

    my $all=get_response("/full/path/to/copyorders_multiple.pl", "refID=". +&trim($license)); my ($data)=$all=~/\n\n(.*)$/s; sub get_response { my ($cgi, $CMD) = shift; ## prepare proper (CGI) environment $ENV{QUERY_STRING} = $CMD; $ENV{REQUEST_METHOD} = 'GET'; $ENV{GATEWAY_INTERFACE} = 'CGI/1.1'; # add more as needed open(CGI, "$cgi |") or die "Can't exec $cgi, $!"; local $/ = undef; my $res = <CGI>; close(CGI) or die "Error running $cgi, $!"; return $res; }

      as an afterthought, that &get_response clobbers %ENV, so you might want to add local %ENV=%ENV; as the first line in sub get_response

      as a second afterthought, my ($cgi, $CMD) = shift; looks strange. i would have used my ($cgi, $CMD) = @_; instead

        Hello huck,

        Thank you but I am on ashared server with no CMD line so when I insert those lines and rem out the old ones I get Internal Server Error.

        This works

        system("copyorders_multiple.pl?refID=".&trim($license)) or die "Unable to get document: $!";

        but how do I add this

        $data = $body();

Re: replace use HTTP::Lite to run a perl file that was on another server
by poj (Abbot) on Feb 19, 2017 at 20:06 UTC

    Why not rewrite the script as a module ?

    poj
      Hello I need to run the copyorder_multiple.pl script from within another script to get the licesne data

        Hi

        This is what poj is talking about, three files, one module, and two cgi programs that use the module

        $ cat MyCopyOrder.pm package MyCopyOrder; sub cgi_run { my $q = CGI->new; my $refID = $q->param('refID'); my $data = MakeData( $refID ); print $q->header, $data; return; } sub MakeData { my( $id ) = @_; ... return $doc; } $ cat copyorders_multiple.pl #!/usr/bin/perl -- use strict; use warnings; use lib '/home/home/mylibs'; ## if needed use MyCopyOrder; MyCopyOrder::cgi_run( ); exit 0; $ cat used_to_call_copyorders_multiple.pl #!/usr/bin/perl -- use strict; use warnings; #~ use HTTP::Lite; #~ my $http = new HTTP::Lite; #~ my $req = $http->request("copyorders_multiple.pl?refID=".&trim($lic +ense)) or die "Unable to get document: $!"; #~ my $data = $http->body(); #~ if (length(&trim($data)) > 0) use lib '/home/home/mylibs'; ## if needed use MyCopyOrder; my $data = MyCopyOrder::MakeData( $license ); ...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1182307]
Approved by beech
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-03-29 01:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found