in reply to Re^3: Running detached processes with Activeperl under IIS
in thread Running detached processes with Activeperl under IIS

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?

Replies are listed 'Best First'.
Re^5: Running detached processes with Activeperl under IIS
by ikegami (Patriarch) on May 12, 2009 at 16:17 UTC

    still waits for the console application t

    Well that's fishy. It can't be detached from and attached to the console at the same time.

    Why does Windows have to be such a pita?

    You have to close the handles and muck with process groups and signals in unix. No easier.

    There are valid complaints against Microsoft and Windows (parameter passing to processes, as a related example), but mind the baseless bashing. DETACHED_PROCESS works fine, and there's nothing complicated about it.

    # launcher.pl use strict; use warnings; use Win32; use Win32::Process; sub ErrorReport{ return Win32::FormatMessage( Win32::GetLastError() ); } my $detached = $ARGV[0]; unlink('foo'); Win32::Process::Create( my $ProcessObj, "c:\\progs\\perl5100\\bin\\perl.exe", q{perl.exe -le"sleep 5; open $fh, '>foo' or die $!; print 'done'"}, 0, NORMAL_PRIORITY_CLASS | ($detached ? DETACHED_PROCESS : 0), '.', ) or die ErrorReport();
    >perl -e"print `perl launcher.pl 0`" & dir /b foo [waits 5 seconds] done foo >perl -e"print `perl launcher.pl 1`" & dir /b foo [returns immediately] File Not Found >perl -e"sleep 5" & dir /b foo foo

    Are you using use strict;?

      I feel like such a doofus sometimes....

      I had commented out use strict while trying to get it working earlier, and left it out (back when I was trying system and exec). I put it back in, and got the "incomplete http headers" message that our server gives when I have an error...and it dawned on me....

      My code was:

      use strict; use warnings; my $child_pid; my $child_proc; print qq~ <html><head><title></title><body> ~; print qq~Testing2<br /><br />~; require Win32::Process; Win32::Process::Create($child_proc, "D:/ipms/bin/Medicaid/Console/Medi +caidEHRService.exe", "MedicaidEHRService 123456", 0, DETACHED_PROCESS +, ".") || print "Could not spawn child: $!"; print qq~</body></html> ~;

      I changed it to:

      use strict; use warnings; use Win32; use Win32::Process; my $child_pid; my $child_proc; print qq~ <html><head><title></title><body> ~; print qq~Testing2<br /><br />~; Win32::Process::Create($child_proc, "D:/ipms/bin/Medicaid/Console/Medi +caidEHRService.exe", "MedicaidEHRService 123456", 0, DETACHED_PROCESS +, ".") || print "Could not spawn child: $!"; print qq~</body></html> ~;

      And guess what...it works! Now I need to go put it in the real code.

      Thanks for all your help!

        I just copied it from the docs. They're probably exactly the same, but maybe not. There was no reason to change it.