in reply to Running detached processes with Activeperl under IIS

All but the last two wait for the exe to finish before completing the script ...

You're misinterpreting the symptoms.

  1. system 1, ... will return to your script immediately.

    The waiting occurs within the web server itself. Here's why.

    When a webserver starts a cgi script, it supplies (via inheritance) that script with it standard handles: stdin; stdout; and stderr. It then waits for those handles to close before it transmits the output from the script to the browser.

    But when you call system 1, ... within the cgi, that child process inherits its standard handles from the cgi script. So, even though your script finishes and perl.exe exits, the standard handles it inherited are still being held open by the new process. So the webserver continues to wait until those handles are closed, which won't be until that new process (MedicaidEHRService.exe) completes.

  2. exec .... Ditto. The process that replaces perl.exe will inherit the standard handles; the webserver waits.
  3. exec "start ...". Ditto again.

    Might work if you added the /b parameter to the start command.

  4. Win32::Process::Create( .... Will probably work once you pass DETACHED_PROCESS correctly.
  5. With the last two, the standard handles are closed, so the webserver detects eof and completes the transaction.

    But, and I can only speculate here as I don't have that particular executable, the program you are running must need the one or more of the standard handles for some reason to work correctly, and fails because they are closed.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^2: Running detached processes with Activeperl under IIS
by Jules (Initiate) on May 12, 2009 at 13:21 UTC

    Thanks for the pointers all.

    I tried adding the /d to the system command, and taking the quotes off of DETACHED_PROCESS...but it still waits....

    However, my exe is a console app...so maybe that's why. I didn't realize there was a difference in the way they are handled.

    I'm going to go back and see if I can convert it to a Windows app and get it to run...maybe that will help.

        Sorry...."but it still waits" was to mean, the parent cgi still waits for the console application to complete. No change from using CREATE_NEW_CONSOLE either.

        Why does Windows have to be such a pita?