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

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; }

  • Comment on Re: replace use HTTP::Lite to run a perl file that was on another server
  • Download Code

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

    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

Re^2: replace use HTTP::Lite to run a perl file that was on another server
by huck (Prior) on Feb 19, 2017 at 19:14 UTC

    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();

        when I insert those lines and rem out the old ones I get Internal Server Error.

        Perhaps because Perl doesn't use "rem" as the comment indicator. Try # instead.

        But thank you for the sudden and unexpected 35 year timewarp back to adolescent me hacking my brains out on BASIC. My $DEITY, those were the days!

        This works just fine for me as a "redirect"

        #!/usr/bin/perl -w my $cgi='/home/huck/cvs/cgi-bins/bt-bin/ut-active.pl'; my $parms='txtstats-1=1'; my $all=get_response($cgi,$parms); #my $all=get_response("/full/path/to/copyorders_multiple.pl", "refID=" +.&trim($license)); my ($data)=$all=~/\n\n(.*)$/s; #print $data; print $all; sub get_response { local %ENV=%ENV; my ($cgi, $CMD) = @_; ## 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; }
        so i dont know what to say, perhaps what Hippo says in Re^4: replace use HTTP::Lite to run a perl file that was on another server is the problem, or you could look in the error log, mine is at /var/log/apache2/error.log, YMMV

        Notice i printed $all, so all the proper headers would be returned to the browser

        EDIT: "as a redirect", means that going to http://lxle0/bt-bin/fakecgi.pl returned the same as going to http://lxle0/bt-bin/ut-active.pl?txtstats-1=1. This is an internal server running apache2 on lxle (ubuntu) and in /etc/apache2/apache2.conf there is

        ScriptAlias /bt-bin/ /home/huck/cvs/cgi-bins/bt-bin/ <Directory /home/huck/cvs/cgi-bins/bt-bin/> Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow from all AllowOverride None Satisfy Any # Require all granted Options +ExecCGI AddHandler cgi-script .cgi .pl </Directory>

        As a lark try this

        my $all=get_response("copyorders_multiple.pl", "refID=".&trim($license +)); my ($data)=$all=~/\n\n(.*)$/s; sub get_response { local %ENV=%ENV; my ($cgi, $CMD) = @_; ## 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; }
        and if it works, SHEESH

        I think you are confused by the variable $CMD which is not the CMD line.

        Maybe this looks better to you:

        sub get_response { my ($cgi, $query) = shift; $ENV{QUERY_STRING} = $query; $ENV{REQUEST_METHOD} = 'GET'; $ENV{GATEWAY_INTERFACE} = 'CGI/1.1'; open(CGI, '-|', $cgi) or die "Can't exec $cgi, $!"; local $/ = undef; my $res = <CGI>; close(CGI) or die "Error running $cgi, $!"; return $res; }

        Note: I used the 3 argument form of open as it is generally safer to use.