Hi Monks,

I am developing a server-driven web application; the structure is the the typical one: A user enters data into a form, and after submission of the form, a CGI script on the server processes the form data. The webserver is Apache 2.x; the CGI script is written in Perl and uses the CGI module to extract the form data. This is working so far.

Let's call the CGI script described above ScriptA.pl.

Now, there is a second CGI script (ScriptB.pl). ScriptB.pl serves two purposes:

1) Like ScriptA.pl, it is called directly from the user's browser and processes form data (it also uses CGI.pm for doing that).

2) Under certain circumstances, it will be called by ScriptA.pl (using "system", "exec" or one of their friends), i.e. there is the following "call chain": User's browser with form ---> ScriptA.pl (via CGI) ---> ScriptB.pl.

I have the following problem: If ScriptB.pl is called from ScriptA.pl, ScriptB.pl must have access to all form data which originally is sent from the user's browser to ScriptA.pl, i.e. the form data must be passed somehow from ScriptA.pl to ScriptB.pl. I have no clue if there is a reasonable way to do that. So far, the following (idiotic) solutions have come to my mind:

- ScriptA.pl might transform the form data into command line parameters which are passed to ScriptB.pl when calling it. This has two serious disadvantages: I surely would have to write code which encodes the form data for the command line (all character sequences which might be treated specially by the shell would have to be transformed), and the form data might be very long, even longer than the maximum length which is allowed for a command line.

- ScriptA.pl might write the form data to a temporary file which is then read by ScriptB.pl. This is very costly (isn't it?), and ScriptB.pl still would have to be told the name of the temporary file.

What do you think about that problem?

Thank you very much,

Nocturnus


In reply to How to pass form data from a CGI script to its child process? by Nocturnus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.