Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

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 ( [id://1182310]=note: print w/replies, xml ) Need Help??


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

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

Replies are listed 'Best First'.
Re^3: replace use HTTP::Lite to run a perl file that was on another server
by bNathan (Novice) on Feb 19, 2017 at 19:51 UTC
    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>

        I would recommend the 3 argument form of open instead:

        open(CGI, '-|', $cgi) or die "Can't exec $cgi, $!";

        as it is generally safer.

      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

          it that doesnt work please answer the following
        • What happens if you go to http://newserver/newpath/copyorders_multiple.pl?refID=somevalidrefid
        • how did copyorders_multiple.pl get on/to the new server
        • Have you checked the executable settings on copyorders_multiple.pl
        • how does copyorders_multiple.pl deal with refID=".trim($license), how are you sure that any required resources or datasets needed by copyorders_multiple.pl are also on the new server?
        • Was the old server a windows machine and the new server a unix or mac machine? if so http://stackoverflow.com/questions/7858987/apache-2-throws-no-such-file-or-directory-exec-of-usr-lib-cgi-bin-fst-cgi may solve your problem.
        There are more problems that could exist, but without the error.log entries it is hard to predict

      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.

        "as a second afterthought, my ($cgi, $CMD) = shift; looks strange. i would have used my ($cgi, $CMD) = @_; instead" Re^2: replace use HTTP::Lite to run a perl file that was on another server

        #!/usr/bin/perl -w my $all=get_response('a','b'); sub get_response { my ($cgi, $CMD) = shift; print 'a'.$cgi."\n"; print 'b'.$CMD."\n"; }
        Result:
        aa Use of uninitialized value $CMD in concatenation (.) or string at x118 +2315.pl line 6. b

        is now in the same cgi-bin directorty as the perl script that is calling for that script. replace use HTTP::Lite to run a perl file that was on another server Taking that to mean that the caller was cgi as well i added 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 because i didnt want a clobbered %ENV to mess up some other part of the cgi script.

        so probably best is

        sub get_response { local %ENV=%ENV; my ($cgi, $query) = @_; ## prepare proper (CGI) environment $ENV{QUERY_STRING} = $query; $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; }
        Tho in this case the 3 arg open didnt mean as much since we know that the $cgi parm had no special characters being hardcoded.

        well at least my first post had added Using get_response from that node and untested and i did look over the code again and again to make sure it was doing what i thought it was and posted addendums to correct what i thought were weaknesses.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2024-04-20 03:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found