aciid
aciid

Reputation: 11

Best way to execute perl script from webpage?

I need to execute a perl script in the root directory of my server from a webpage (on same server). 4 parameters need to be passed to this script from input boxes on the page for it to work.

What would be the best way to do this? Please advise. If possible please provide an example.

Many thanks

Upvotes: 1

Views: 13905

Answers (3)

Brigand
Brigand

Reputation: 86230

Servers like Apache have a /cgi-bin/ handler. You would make a request to

http://site.tld/cgi-bin/script.pl?param=val&param2=val

or something similar. This script.pl actually resides elsewhere. One common location is /usr/lib/cgi-bin.

I made a quick screen cast about how this would be done. I've only done this for Python before, so this was a learning and teaching at once for me.

Links from the video:

This is the end result of the video

I type comments on the command line explaining certain parts. One that I usually forget is to chmod the scripts. If they aren't executable, the server won't execute them and you'll have no idea why.

Upvotes: 3

dyoo
dyoo

Reputation: 12023

Your web server's software defines an interface to cooperate with external scripts. The most prevalent of these is the Common Gateway Interface (CGI). Without knowing more about your server's setup, we can't say anything more specific.

If you are using Apache, take a look at http://httpd.apache.org/docs/2.0/howto/cgi.html which tells how to set CGI up.

There are other approaches to this, and they all depend intimately on the particular server software you are running.

Upvotes: 1

gpojd
gpojd

Reputation: 23065

Why not have the webpage post a form to a CGI script that calls the perl script (or make the perl script the CGI page)?

Upvotes: 0

Related Questions