"S.Lee" wrote:
>> Thank you very much, Rick.
>> I tried your code snippet and it worked great in initializing GCG
> environment when run FROM THE SHELL.
The code you posted would not have worked from the shell either so I'm
not
sure how you judged it to have worked...
> However, it still does not run ON THE WEB. It does not produce an output
> file.
>> Could you please take a look at my CGI script and let me know what is going
> on? (Of course, I chmod'ed the output directory writable to ugo, so writing
> privilege issue cannot be the reason).
I think a bit of error checking is in order. A modified and commented
version
of your code is below.
Hope this helps
Simon.
------------------------------------------------------------
#!/usr/sbin/perl
# Always put on your safety belt!
use warnings; # Add -w to the first line if using perl <5.6
use strict;
# For convenience let's look at our errors in
# the browser
use CGI::Carp qw(fatalsToBrowser);
my $execstr = "/usr/users/gcg/gcgbin/execute/tofasta
SP_BA:Q93J69 -OUTfile=/SOME_DIRECTORY/out.tfa -default";
my $tmpname = "tmpdir.gcgtmp";
# Where do you think this file will be created? Many
# web servers will have a very different idea about the
# current working directory than you have!
chdir('/somewhere_my_web_server_can_write_to/') || die "Can't chdir:
$!";
open (GCGFILE,">$tmpname") || die "Can't create $tmpname: $!";
# ***********************************
# You should always check that an open succeeds
### print $GCGFILE "#!/bin/tcsh\n";
### etc.
#
# These lines don't do what you think they do. You are
# trying to print to $GCGFILE, a new variable you have just
# created, rather than printing to GCGFILE, the filehandle
# you tried to open before. Use strict would have
# caught the creation of a new variable, but you should have
# seen a warning saying "Can't use an undefined value as a
# symbol reference" anyway...
print GCGFILE <<"END_OF_SCRIPT";
#!/bin/tcsh
source /usr/gcg/gcgstartup
gcg
$execstr
END_OF_SCRIPT
close (GCGFILE) || die "Can't close GCGFILE: $!";
chmod (0700,$tmpname) || die "Can't chmod: $!";
print <<"END_HTML";
Content-type: text/html
<html>
<body>
<pre>
END_HTML
print `./$tmpname 2>&1`;
# Here I've executed the command in backticks
# to grab it's output. I've also redirected
# stderr to stdout so you should see any errors
# which occur
unless (-e '/SOME_DIRECTORY/out.tfa'){
print "Nope - Something went wrong\n";
}
print '</pre></body></html>';