Hmmm...I'm not completely understanding your post, so I'll just post all my code here. I suppose it might be possible to do this all using a single CGI script, but I found it easier just to implement it as two separate scripts, so I didn't have to detect what state I should be in. The way I'm handing the transaction to the second script is through a form with a file upload in it. Do you get the output on the screen from the second script?
convert_word1.cgi:
#!/usr/bin/perl
use strict;
use CGI;
use Digest::SHA1;
use URI::Escape;
use Tetragon;
my $q = new CGI;
print Tetragon::html_header();
print <<STUFF;
<h2>Converting an MS Word File</h2>
<p>
This web-based program is designed to convert a fiction manuscript fro
+m MS Word format
to plain text format. The main advantage of this over a simple "Save a
+s" in Word is
that it will automatically format italics <tt>_like this_</tt> and bol
+dface
<tt>*like this*</tt>. Once you upload your file, the resulting convert
+ed
version will be displayed in your browser, and you can cut and paste i
+t into
a text editor such as NotePad.
</p>
<p>Caveats:</p>
<ul>
<li>This is a fairly computation-intensive thing for my server to do,
+so I don't want this
to be a service that's used heavily by a huge number of people. Pl
+ease don't
use it from an automated script, and don't use it more than a few
+times per day.</li>
<li>Don't assume blindly that the results are what you want. Look over
+ the output file
carefully, and fix any problems by hand.</li>
<li>This probably will not work with the OOXML format used as the defa
+ult format by the most recent
versions of word. To make sure that's not a problem, do a "Save as
+" in Word, and choose
an older format.</li>
</ul>
STUFF
print <<STUFF;
<form method="post" action="http://tetragonsf.com/cgi-bin/convert_word
+2.cgi" enctype="multipart/form-data">
<p>file: <input type="file" name="foo" size="40"/></p>
<p> <input type="submit" name="Continue" value="Continue" /> <
+/p>
</form>
STUFF
print Tetragon::html_footer();
convert_word2.cgi:
#!/usr/bin/perl
use strict;
use CGI;
use Digest::SHA1;
use Tetragon;
use IO::File;
use POSIX;
use constant UPLOAD_DIR => "/usr/local/www/tetragonsf/uploads"; # not
+clear to me that this actually has any effect
use constant BUFFER_SIZE => 16_384;
use constant MAX_FILE_SIZE => 2_000_000;
use constant MAX_DIR_SIZE => 500_000_000;
use constant MAX_OPEN_TRIES => 100;
$CGI::DISABLE_UPLOADS = 0;
$CGI::POST_MAX = MAX_FILE_SIZE;
my $q = new CGI;
print <<'HEADER';
Content-type: text/plain
HEADER
my $filename = $q->param('foo');
my $fh = $q->upload('foo');
my $buffer = '';
my $t = '';
binmode $fh;
while (read($fh,$buffer,BUFFER_SIZE)) {
$t = $t . $buffer;
}
my $in;
do {$in = POSIX::tmpnam()} until ! -e $in;
my $out;
do {$out = POSIX::tmpnam()} until ! -e $out;
open(F,">$in") or die "error opening temporary file for doc";
binmode F;
print F $t;
close F;
system("/home/bcrowell/Documents/programming/scripts/fiction_word_to_t
+xt <$in >$out")==0 or die "error executing fiction_word_to_txt";
local $/; # slurp whole file
open(F,"<$out") or die "error reading output of fiction_word_to_txt";
my $txt = <F>;
close F;
unlink $in;
unlink $out;
print $txt;
|