Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi i am new to cgi. i want to run the perl exe file in cgi form.
that is from cgi user input then the perl exe should take the given argument and then run.
Thanks in advance.

Replies are listed 'Best First'.
Re: How to run the perl exe in cgi script?
by jhourcle (Prior) on Mar 17, 2005 at 14:42 UTC

    Rather than guess at every permutation of possible answers, could you give a clue as to what your OS and webserver is? (I'm guessing it's some form of windows, as most unix folks refer to it as 'perl' and not 'perl exe', but it might be a local reference).

    If you're using some form of unix, and it's configured to be run as a CGI (again, how to do that depends on the webserver), you just have the first line be:

    #!/your/path/to/perl --

    (but putting in the correct path for your system

    (I'm also guessing this is most likely a FAQ, but I find it hard to scan through the CGI Q&A list.)

Re: How to run the perl exe in cgi script?
by Joost (Canon) on Mar 17, 2005 at 14:49 UTC
Re: How to run the perl exe in cgi script?
by chas (Priest) on Mar 17, 2005 at 21:47 UTC
    You could use the system function to run perl on some args supplied as CGI input, but this can be very dangerous since a user could enter commands which when fed to perl erase things in your web directory, for example (or worse.) It is really quite easy for this to happen. You should certainly use Taint mode and check all input very carefully. In fact, I've never done anything like that just because I'm afraid I might overlook some security pitfall. It is safer if you have a fixed set of commands that can be fed to perl and just allow those (perhaps checking if user input matches one of the allowed ones.) I'm not sure this is what you meant, but it sounded like that. (If you exhibit your script here, I'm sure you will get valuable advice about possible problems.)
    Check out Ovid's cgi course for examples of pitfalls and a lot more.
    chas
Re: How to run the perl exe in cgi script?
by Anonymous Monk on Mar 17, 2005 at 14:48 UTC
    update:
    server: apache
    o/s : windows 2000 professional.
    I have done the perl programme as executable. When i click the button or link the executable file as to process.
    please provide the sample code if possible.
      I suggest the following steps:
      1. Generate a list of the relevent terms. (I suggest 'apache windows cgi perl')
      2. Type those terms into Google.
      3. Follow any one of the tutorials on the subject

      (one of the answers even came from this site).

      And in this case, most programs under windows all run the same, so long as there isn't a major version change in the program itself. (the problem is that the items like IIS, that ship with windows, tend to change major versions between minor OS version changes).