我如何打电话的Perl CGI脚本从其他的Perl CGI脚本 [英] How do I call perl cgi script from another perl cgi script

查看:202
本文介绍了我如何打电话的Perl CGI脚本从其他的Perl CGI脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个CGI脚本这需要几个参数,如下图所示。

I have a cgi script which takes few parameter like below.

testScript.cgi?arg=1&arg2=SomeThingElse&arg3=otherThing.....

以上脚本运作良好,并完美的。

The above script works well and perfectly.

现在我有另一个名为perl的CGI脚本 mySecondScript.cgi 。它做自己的事情,但我想打电话给 textScript.cgi 与在此脚本计算参数。我怎么做。任何优雅的解决方案将是AP preciated。

Now I have another perl cgi script called mySecondScript.cgi . It does its own thing but I want to call textScript.cgi with arguments which are calculated in this script. How do I do that. Any elegant solution will be appreciated.

推荐答案

您可能需要使用 LWP: :简单调用第二个程序。内部mySecondScript.cgi你需要的东西是这样的:

You probably want to use LWP::Simple to call the second program. Inside mySecondScript.cgi you would need something like this:

my $output = get("http://someserver.somedomain/testScript.cgi?arg=1&arg2=SomeThingElse&arg3=otherThing");

这将返回从CGI程序的输出(即HTML页面,它生成)。如果你想在你得到什么更多的控制,那么你需要使用 LWP :: UserAgent的

This will return the output from the CGI program (i.e. the HTML page that it generates). If you want more control over what you get back, then you need to use LWP::UserAgent.

my $ua = LWP::UserAgent->new;
my $resp = $ua->get("http://someserver.somedomain/testScript.cgi?arg=1&arg2=SomeThingElse&arg3=otherThing");

$ RESP 将是一个 HTTP ::响应对象。

可替换地,如果两个程序都本地运行,这可能是更方便testScript.cgi的重要位重构成可以只加载并mySecondScript.cgi中使用的模块。

Alternatively, if both of your program are running locally, it might be more convenient to refactor the important bits of testScript.cgi into a module that you can just load and use within mySecondScript.cgi.

这篇关于我如何打电话的Perl CGI脚本从其他的Perl CGI脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆