axl163 has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks,
I know it's Friday but I hope there is someone out there can help me with my situation. I have a cgi file that needs to execute another file without having the browser wait for the outcome of the execution. Here is a little diagram:
The code that I have is not working like the way I want because when I make the request to the cgi file, the browser waits for all processes to finish before closing the connection. I just need to execute "launch" and I do not need it to wait for it to finish before sending back the "successful submit" message. I think I am really close and this will probably involve forking and the use of exec() or even system() but this is what I have so far:
I have edited the code according to runrig's suggestion but I'm not sure if I did it right.
Any suggestions would be greatly appreciated. Thanks in advance.
newb
I know it's Friday but I hope there is someone out there can help me with my situation. I have a cgi file that needs to execute another file without having the browser wait for the outcome of the execution. Here is a little diagram:
browser->request->cgi->execute another program | return submitted successful message and close connection without waiting for the other process
The code that I have is not working like the way I want because when I make the request to the cgi file, the browser waits for all processes to finish before closing the connection. I just need to execute "launch" and I do not need it to wait for it to finish before sending back the "successful submit" message. I think I am really close and this will probably involve forking and the use of exec() or even system() but this is what I have so far:
I have edited the code according to runrig's suggestion but I'm not sure if I did it right.
chdir '/' or die "Can't chdir to /: $!"; open STDIN, '/dev/null' or die "Can't read /dev/null: $!"; open STDOUT, '>/dev/null' or die "Can't write to /dev/null: $!"; my $pid = fork(); if (not defined $pid) { print "resources not available.\n"; } elsif ($pid == 0) { #this is where I launch the other executable system("/usr/local/bin/launch myfile &") or die("Cannot execute la +unch: $!\n"); exit; } else { setsid or die "Can't start a new session: $!"; open STDERR, '>&STDOUT' or die "Can't dup stdout: $!"; #this is the return message print "Your file has been sent successfully. You will be notified + via email once it has been completed. Thank you."; print end_html(); exit; }
Any suggestions would be greatly appreciated. Thanks in advance.
newb
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Fork() and exec()
by graff (Chancellor) on Oct 27, 2007 at 00:27 UTC | |
Re: Fork() and exec()
by runrig (Abbot) on Oct 26, 2007 at 23:01 UTC | |
Re: Fork() and exec()
by tuxz0r (Pilgrim) on Oct 27, 2007 at 00:39 UTC | |
Re: Fork() and exec()
by axl163 (Scribe) on Oct 27, 2007 at 00:57 UTC | |
Re: Fork() and exec()
by axl163 (Scribe) on Oct 27, 2007 at 01:00 UTC | |
Re: Fork() and exec()
by neversaint (Deacon) on Oct 27, 2007 at 14:48 UTC |
Back to
Seekers of Perl Wisdom