in reply to Outputting to browser vs DOS...how can you tell?

Is there an easy check to tell if a script is being invoked from within a DOS shell vs from a browser

This may be a little more than you are really looking for, but it is a quick example of how to extend your tool.

#!/usr/bin/perl -w use strict; use Getopt::Long; use vars qw: %switches %actionTable @logActions :; %actionTable = ( 'email' => \&_logEmail, 'browser' => \&_logBrowser, 'console' => \&_logConsole, 'file' => \&_logFile, ); $|++; &GetOptions( \%switches, "email:s", ## script provides a default if none given "file=s", ## MUST have a file name if you want to log to a +file "console", ## console can be target "browser", ## or browser can be target( or both.. ) "url=s", ## url to begin from "help" ## jsut a usage thing ); ## are we just looking for help? if ( $switches{ 'help' } ) { print <<EOHELP; switches: --url <url> site you want to work on --email <address or default if blank> to save output to ema +il --file <file to open> to save output to file --console to use console format --browser to use browser format --help this page EOHELP exit(0); } ## build our @logActions so we know what we have to log to if ( defined( $switches{ 'email' } ) ) { ## we have an email, but it may be empty string, so use default ## notice class act style here! $switches{ 'email' } = 'root@localhost' if ( $switches{ 'email' } +eq "" ); ## open email here if you are going to use it ## ie open( EMAIL, "| /usr/sbin/sendmail -blah )... push( @logActions, 'email' ); } if ( defined( $switches{ 'file' } ) ) { ## open our file, do your security checking too ## open( FILE, '>' . $switches{ 'file' } ) ... push( @logActions, 'file' ); } if ( $ENV{ 'REMOTE_HOST' } ) { ## don't print console data if from browser ## this could be better, but for the sake of an example it'll do $switches{ 'console' } = 0; $switches{ 'browser' } = 1; } ## note no real error checking if no file/email/console/browser select +ed ## legal and illegal combinations are up to the reader push( @logActions, 'console' ) if $switches{ 'console' }; push( @logActions, 'browser' ) if $switches{ 'browser' }; ## do you stuff print '-' x 11, ' START ', '-' x 11, "\n"; output( 'test message a' ); output( 'test message b' ); output( 'test message c' ); print '-' x 11, ' END ', '-' x 11, "\n"; exit(0); sub output { my $text = shift; defined( $actionTable{ $_ } ) && &{$actionTable{ $_ }}( $text ) fo +reach @logActions; } sub _logConsole { print "Console: $_[0]\n"; } sub _logBrowser { print "Browser: <p>$_[0]</p>\n"; } sub _logEmail { ## print EMAIL "$_[0]\n"; print "Email: $_[0]\n"; } sub _logFile { ## print FILE "$_[0]\n"; print "File: $_[0]\n"; }

I know I find the command line much easier to work with, so I hope this helps you. Also, remember this is just an example, there is a lot left to work out.

Will perl for money
JJ Knitis
(901) 756-7693
gt8073a@industrialmusic.com