studious monks, why does this code work? it does what I want, but doesn't exactly look like it should. the root of the problem i think is that i don't really *get* fork()
#!/usr/bin/perl use warnings; use strict; $|++; # running in Apache 1.3.34 print "Content-Type: text/html\n\n"; print "OK"; fork(); close STDOUT; qx/ some_cmd /;
What this apparently does, which I want it to do, is print OK and then execute some_cmd, and the browser recieves the string "OK" and a closed HTTP connection BEFORE (or AS) that qx occurs. I want those 2 events to be as close as possible as I can get it, connection closure and qx/ some_cmd / - but why

Update: I guess I wasn't very clear on what I was asking, a lot of people are telling me that fork will make some_cmd execute twice, which on the command line is true. But when run by apache, close STDOUT apparently does something magic, some_cmd is executed once. I'd expect it to execute either 0 times or twice, but once? wth?

It's not what you look like, when you're doin' what you’re doin'.
It's what you’re doin' when you’re doin' what you look like you’re doin'!
     - Charles Wright & the Watts 103rd Street Rhythm Band, Express yourself

In reply to explain my fork by qbxk

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.