homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

Pass parameters to an #exec cgi instruction

 10:52 am on Jun 24, 2013 (gmt 0)

Hi Everyone,

I am trying to pass parameters to a perl script using

<!--#exec cgi="/cgi-bin/mywebsite/myscript.pl?param1=value1&param2=value2" -->

but it doesn't seem to work.

Can I do something like

<!--#include virtual="/cgi-bin/mywebsite/myscript.pl value1 value2" -->

instead ?

If not, what is the recommended way ?

Thank yo for your help.



 12:01 pm on Jun 24, 2013 (gmt 0)

welcome to WebmasterWorld, chapo!

The include virtual element should be used in preference to exec cgi. In particular, if you need to pass additional arguments to a CGI program, using the query string, this cannot be done with exec cgi, but can be done with include virtual, as shown here:
<!--#include virtual="/cgi-bin/example.cgi?argument=value" -->


 12:53 am on Jun 25, 2013 (gmt 0)

Thank you for your answer.

What I need to do is have a mix of "local" variables (that I would pass as arguments of the
#include virtual) and "global" variables in the URL of the webpage.

So I need to use CGI within my
#include virtual for "global" as well as "local" variables but it doesn't seem to work. It allows me to get the "local" variables with cgi->param("myvariablename") but it won't detect the "global" ones.

Any pointers ?



 1:18 am on Jun 25, 2013 (gmt 0)

You can set variables using SSI. These would be available to the script if they are set before the script is called:

<!--#set var="widget" value="red" -->

You can also pass environmental variables to the script by prepending a $ character to the env name:

<!--#include virtual=/cgi-bin/example.cgi?ip=$REMOTE_ADDR" -->

Hope this helps.


 1:27 am on Jun 25, 2013 (gmt 0)

Sorry I am a bit of a newbie here but what is the difference between a regular variable on my webpage and an environmental variable ?

Let's say my URL looks like www.blabla.com/index.shtml?dt=20130625
And I want to use dt (20130625) as one of the parameters to my Perl script. Is that doable using your syntax of #include virtual ?


 1:43 am on Jun 25, 2013 (gmt 0)

You're passing a query string parameter to your perl script. This is stored in environmental variable QUERY_STRING. What you need to do is parse $ENV{'QUERY_STRING'} for dt=value


 1:51 am on Jun 25, 2013 (gmt 0)

I am not though.

My URL is as above (www.blabla.com/index.shtml?dt=20130625) but the call to my script is done through an include virtual

<!--#include virtual="/cgi-bin/mywebsite/myscript.pl?param1=value1&param2=value2" -->
and the QUERY_STRING variable only contains what I have called the "local" variables (param1 and param2).

dt=20130625 is not part of the QUERY_STRING.

What I would like to do is have
<!--#include virtual="/cgi-bin/mywebsite/myscript.pl?param1=value1&param2=value2&dt=20130625" -->

where the dt=20130625 is dependant on what is in the URL (I can also store the 20130625 value in a variable)

Have I misunderstood something ?


 2:05 am on Jun 25, 2013 (gmt 0)

Maybe I am misunderstanding something. Where is dt=20130625 coming from? If it's a query string parameter in the url of the page that is using SSI you can try:

<!--#include virtual="/cgi-bin/mywebsite/myscript.pl?param1=value1&param2=value2&$QUERY_STRING" -->


 2:09 am on Jun 25, 2013 (gmt 0)

Great that did the trick !
Thank you very much for your help.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved