Take the 2-minute tour ×

I have a third party Perl script designed to be executed by a browser and which processes data in a HTTP POST request.

The script can be executed from the command line but when doing so it is not being executed in the expected environment and as such does not have access to required user data.

I need to execute the script very frequently and want to avoid the overhead of spinning up an Apache process to handle what can instead be handled at the command line. The script executes from the command line much much much faster than via Apache (at least with no input data).

I'd like to wrap up the script such that command line arguments are passed to the script as if they were present in a HTTP POST request.

I'm not very familiar with Perl and would like to present a (rudimentary) example in PHP to represent what I intend to achieve.


$_POST['example1'] = $argv[1];
$_POST['example2'] = $argv[2];

include /var/www/thirdPartyScript.php


The Perl script accesses data as follows:

#!/usr/bin/perl -T

use CGI 3.40 qw(-newstyle_urls -private_tempfiles redirect);
# ...
my $q = CGI->new();
# ...
if ($q->param('example1') {

} else {


What would the wrapper script need to set such that the third party script has access to relevant data as if that data were provided in a HTTP POST request?

share|improve this question

2 Answers 2

up vote 5 down vote accepted

If the third party script is CGI, you can provide the parameters on the command line:

your_script.pl name1=value1&name2=value2

See more details on how to test the POST and GET methods in the CGI.pm documentation.

share|improve this answer
Thanks, I'll give this a go now! –  Jon Cram Oct 18 '12 at 7:23

You can easily make a real HTTP request for testing purposes:

use LWP::UserAgent qw();
my $ua = LWP::UserAgent->new;
        foo => 23,
        bar => 42,

You can initialise the CGI object from a hashref or a file.

use CGI qw();
my $c = CGI->new({
    foo => 23,
    bar => 42,

Prefer real HTTP requests over these fake ones! The fake ones, including the command-line variant in January's answer, lack some properties, e.g. request_method.

share|improve this answer
Thanks, I appreciate the concept. In this case I'm explicitly avoiding making an HTTP request to avoid the overhead of spinning up an Apache process to deal with it. Nice answer, not relevant. –  Jon Cram Oct 19 '12 at 9:33
+1 For providing a general answer. Thank you! –  Bloodcount Jul 1 at 9:16

Your Answer


