http://www.perlmonks.org?node_id=620936
ultibuzz has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,
i'm having problems with bufferoutputs after i upload something with a multipartform.

basicly i launch background scripts with a system(1,cmd,arg), so i don't need to mess with threads or fork, and i don't need to monitor the launched script.
here is a SUB where i'm launching a background script and everything works well
The Sub (code reduced)

my $sth_cs = $dbh->prepare(q~update script_run_rules s +et running=1,run_user=? where NAME='InvDispute'~) or die "Couldn't pr +epare statement: " . $dbh->errstr; $sth_cs->execute($u_email); my @args = ("c:\\Apache2.2\\script_run\\exec_invdisput +e.pl", $u_email); system( 1,$cmd, @args ); print header; print Header_HTML(); print<<HTML; <table width="745" border="0" align="center" cellpaddi +ng="0" cellspacing="0"> $balken $scr_menue <tr><td>&nbsp;</td></tr> <tr><td align="center"><p>script started you will get +an email when it's finished</p></td></tr> $logo </table></body></HTML> HTML
and this is the background script (code reduced)
my $sth = $dbh_o->prepare(q~GIANT MIGHTY SQL STATEMENT~) or die "Couldn't prepare statement: " . $dbh_o->errstr; open(OUT,'>',"c:\\Apache2.2\\script_run\\Calldetails_".$inv_nr +.".txt") or die("open failed: $!"); $sth->execute($inv_nr); while (my @data = $sth->fetchrow_array()) { print OUT join(';',@data),"\n"; } $dbh_o->disconnect; close(OUT);

so system( 1,$cmd, @args ); calls the external script and the user can messaround with the site, the launched script finishes the work and send an email to the user when his output is ready.


Now some other sub with the difference of uploading a file with informations (code reduced)

binmode $filehandle; open OUT, "> c:\\Apache2.2\\script_run\\BV_on_acc.txt" + or die $!; binmode OUT; { my $buffer; while ( read $filehandle, $buffer, 1024 ) { print OUT $buffer; } } close OUT; close $filehandle; my $sth_cs = $dbh->prepare(q~update script_run_rules s +et running=1,run_user=? where NAME='BVonAcc'~) or die "Couldn't prepa +re statement: " . $dbh->errstr; $sth_cs->execute($u_email); my @args = ("c:\\Apache2.2\\script_run\\exec_bvonacc.p +l", $u_email); system( 1,$cmd, @args ); print header; print Header_HTML(); print<<HTML; <table width="745" border="0" align="center" cellpaddi +ng="0" cellspacing="0"> $balken $scr_menue <tr><td>&nbsp;</td></tr> <tr><td align="center"><p>script started you will get +an email when it's finished</p></td></tr> $logo </table></body></HTML> HTML }

and the background script (code reduced)
system('sqlldr.exe CREDS CONTROL=C:\Apache2.2\script_run\bv_on_acc_loa +der.ctl'); my $sth = $dbh_o->prepare(q~MIGHTY SQL STATEMENT~) or die "Couldn't pr +epare statement: " . $dbh_o->errstr; open(OUT,'>',"c:\\Apache2.2\\script_run\\$file") or die("open failed: +$!"); $sth->execute(); while (my @data = $sth->fetchrow_array()) { print OUT join(';',@data),"\n"; } $dbh_o->disconnect; close(OUT);

so system( 1,$cmd, @args ); launches the backgroud script.
but now the launched script pushes back the buffer output to the main CGI site,data flows during the whole time the background process runs and the site is unusable.

i checked the search about buffer CGI and apache and i found some tips, and tryed them but nothing works.
this only happens when the launching sub uses a multipartform.
i really apreciate any idear or tipp how to solve this

kind regards
ultibuzz

PS: i hope the readmore's are working