Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Windows Background forking in Perl /HTTP Error Capture

by suzun30 (Acolyte)
on Mar 12, 2014 at 21:53 UTC ( #1078102=perlquestion: print w/ replies, xml ) Need Help??
suzun30 has asked for the wisdom of the Perl Monks concerning the following question:

Hi I am having a web page which accepts an input excel file and does some processing and presents the output to the user for download via a link. After it does this, it continues to do some more processing on that file in the background, which I am attempting to achieve by using exec(bgscript.pl args). I am running my webpage via IIS 6,on windows platform with activestate perl 5.8. The issue is the exec does not really seem to be happening after the display of the page to the user. The page still waits for the bg process to complete and then displays the output. While in most cases this is almost not noticeable since the processing time is minimal for both operations to complete, but in others its not and I get "page cannot be displayed" error. Is there a way to capture this error or make sure exec does not interfere with the page display. Appreciate any inputs. Thank you

Comment on Windows Background forking in Perl /HTTP Error Capture
Re: Capture HTTP Error CGI Perl
by Laurent_R (Parson) on Mar 12, 2014 at 23:35 UTC
    As far as I know, the exec command does not launch the argument program in background mode. It launches the program in the foreground and never returns to the Perl program. But the Perl program really appears to end when the argument program completes. This is an example on Unix of an exec command taking a bit of time to execute:
    $ time perl -e 'print "start program. \n"; exec ("time ls -lR /usr | w +c");' start program. 36311 269214 1917392 real 0m8.933s user 0m1.309s sys 0m3.883s real 0m9.012s user 0m1.339s sys 0m3.929s
    The command passed to exec is counting all the files in the /usr directory and all its subdirectories. It takes a bit of time since there are more than 36000 entries. Under Unix, the time program measures the execution time. The first report states the time taken by the exec command. The second one gives the time taken by the Perl program. As you can see, the Perl program completed only after the exec command finished. No background process here. Under Unix, I could launch my command in the background this way:
    $ time perl -e 'print "start program. \n"; exec ("time ls -lR /usr | w +c &");' start program. real 0m0.090s user 0m0.045s sys 0m0.030s Laurent ~ $ 36311 269214 1917392 real 0m4.102s user 0m1.200s sys 0m2.963s
    Here, the exec command is really launched in the background and the Perl program completes immediately (after 0.09 sec.) and the exec command prints the result and completes 4 seconds later. I do not know how you would do that under Windows, but you might have to launch an intermediate xxx.bat script that launches the background process and exits immediately.
      Hi Laurent, Thanks for your response. Ok. That makes sense. However, still not sure how to acheive this in Windows. I have been looking for several options online and a lot are very skeptical about forking in windows and all I tried so far has not worked.I tried the fork() emulation in perl for windows. It just never seemed to run the background script, though it did return a pid. I will explore the .bat option. Thanks for your inputs again. Appreciate it.
        I have also tried Proc::Background::Win32 with not much result. It still seemd to wait for the process to finish. I did do the Close STDOUT,STDIN,STDERR filehandles part. Any inputs on this or how to capture a HTTP Error code would help. Thanks in advance.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1078102]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2014-08-29 11:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (280 votes), past polls