The other monks are correct, 'exec' never returns. Never.

I would suggest changing the CGI script to give the user a message like "Your file is being processed" and just end.

Then in the background, you need a listener program that watches that directory for new files, picks them up in turn, and processes them. The one I wrote is a shell-script that runs a Perl script every 10 seconds, and is started by rc.local. If you want it to process multiple files at a time, a thread pool can be your friend.

If you need to keep users informed about how their files are going, a CGI script that displays results from a status table, updated by the worker threads, might make sense. (You could even make it part of the original script with a refresh, if you want that 'interactive application' style.)

--
Spring: Forces, Coiled Again!

In reply to Re: system or exec in a web environment by paulbort
in thread system or exec in a web environment by Perimus

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.