in reply to How can a script know if it's a cgi?

It depends on your server environment... how are the CGIs being invoked?

You could check $ENV{GATEWAY_INTERFACE}, though it might be a mod_perl only thing. (haven't written straight CGI in a while...) This code is invoked before any of my mod_perl scripts are run.

# make sure we are in a sane environment. $ENV{GATEWAY_INTERFACE} =~ /^CGI-Perl/ or die "GATEWAY_INTERFACE not P +erl!";

You could compare dumps of the %ENV hash, when invoked from the command line vs. CGI. Something like:

print "$_ => $ENV{$_}<BR>\n" for (keys %ENV);

-Blake