Re: Is this possible in Perl?



Bill H <bill@xxxxxxxxx> wrote:
I have a perl routine that takes some html form variables that are
"POST"ed to it from a Flash app (works the same as a web page POST)
and when it is done it sends back a status to the Flash program using
a simple:

print "Content-type:text/plain\n\n";
print "status=complete";

Perhaps things will already work when you append a "\n" to that
last line? It could happen that a line without a trailing new-
line gets stuck in some internal buffers and only gets send to
the parent process when your script exits and all open files are
closed after the buffers are flushed. Or do

$| = 1;

to make sure stdout is unbuffered.

exit;

which works fine. What I would like to do is send the above so that
the Flash app goes about its business but have the perl program
continue on doing some stuff that I don't want the user to have to
wait for the completion of. What I am looking for is a way to simulate
whatever perl does for the waiting user when it performs the exit
without exiting. Something like this:

print "Content-type:text/plain\n\n";
print "status=complete";
"some magical perl command to force the above to the user
and end connection without stopping program"

additional code that is executed
exit;

If appending a newline to the last line of ouput or setting
auto-flushing for stdout doesn't do the job I guess it's only
in parts a Perl issue and involves also the behaviour of the
process that started the Perl script. The question is: is what
the process that started your script waiting for. Is it waiting
for the stdout of yor script to become closed or is it waiting
for your script to exit? That would seem to me the most likely
scenarios. Thus you could try to do what that process is waiting
for, i.e. in the first case close stdout (and perhaps stderr)
and in the second fork() (to get a new process) and exit in the
parent process. I would try something like this:

close STDIN;
close STDERR;
exit 0 if fork;

The first two lines close stdin and stderr, just to make sure
all buffers are flushed, and the last one ends the parent pro-
cess while creating a new process for continuing with whatever
you still may have to do. If that works you can try if leaving
out the fork() also works. (But note: that's from a UNIX per-
spective, I have no idea how things work under Windows..)

Regards, Jens
--
\ Jens Thoms Toerring ___ jt@xxxxxxxxxxx
\__________________________ http://toerring.de
.



Relevant Pages

  • Re: Call tool from VBA
    ... In VBA (note the 2nd WorkPathUnix on the cmd line is a parm to the perl ... ' For info on DoShellScript See ... MsgBox ("Aborting: problem with perl script") ... Exit Sub ...
    (microsoft.public.mac.office.excel)
  • Re: [PATCH 1/3] Replace kernel/timeconst.pl with kernel/timeconst.sh
    ... The new shell script ... it gave me different results than the perl version for 250 and 1000: ... +trap "rm $FILENAME" EXIT ...
    (Linux-Kernel)
  • script whose execution behaves differently...
    ... trap 'waiting; exit' SIGINT SIGQUIT SIGTERM ... echo background process ended ... When running the script on box A, ...
    (comp.unix.shell)
  • Re: script EXIT not working.
    ... there is nothing grep can read from. ... This is never reached (and not required because the script would exit ... exiting because it is *waiting* for input. ...
    (comp.unix.shell)
  • Re: Is this possible in Perl?
    ... "POST"ed to it from a Flash app ... whatever perl does for the waiting user when it performs the exit ... the process that started your script waiting for. ...
    (comp.lang.perl.misc)