help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-smalltalk] How to access environment variables ?


From: Mehul N. Sanghvi
Subject: Re: [Help-smalltalk] How to access environment variables ?
Date: Tue, 10 Feb 2009 09:01:03 -0500
User-agent: Mozilla-Thunderbird 2.0.0.19 (X11/20090103)

Stephen said the following on 02/10/2009 06:55 AM:


I am trying to use it in a CGI script and get the entire CGI environment. The above works, but it gives me the shell environment variables. Two different things.

My understanding is that with CGI all the parameters are only available to the process as environment variables. I googled a BASH script and a Perl script, and then compared with the simple GST script below. When run on Linux I can extract the same information with all three scripts. Are you getting different results on your platform?

--------------------------
PERL demo CGI script
#!/usr/bin/perl
##
##  printenv -- demo CGI program which just prints its environment
##

print "Content-type: text/plain\n\n";
foreach $var (sort(keys(%ENV))) {
   $val = $ENV{$var};
   $val =~ s|\n|\\n|g;
   $val =~ s|"|\\"|g;
   print "${var}=\"${val}\"\n";
}

--------------------
GST demo CGI script

#!/usr/local/bin/gst -f

Transcript showCr: 'Content-type: text/plain'; nl.

cgivars := {'SERVER_SOFTWARE'. 'HTTP_ACCEPT'. 'HTTP_HOST'. 'REQUEST_URI' }.
cgivars do: [ :env |
   Transcript showCr: env,':',(Smalltalk getenv: env)].

Transcript nl; showCr: '==== All Env Vars below ==============';nl.
pipe := FileStream popen: ('set',logFile) dir: FileStream read.
Transcript showCr: pipe contents.
! !

Regards
Stephen





====== PERL SCRIPT =======
print "Content-type: text/html\n\n";
print "<HTML>\n";
print "<HEAD><TITLE>Testing CGI/Perl</TITLE></HEAD>\n";
print "<BODY>\n";
print "<H2>Yo! Perl,   Whats up ? </H2>\n";

print "<tt>\n";
foreach $key (sort keys(%ENV)) {
    print "$key = $ENV{$key} <br>" ;
}

print "</BODY>\n";
print "</HTML>\n";


exit (o);

====== END PERL SCRIPT =====

====== PERL OUTPUT IN WEBPAGE =====
Yo! Perl, Whats up ?
CONTENT_LENGTH = 0
DOCUMENT_ROOT = /var/www/www.sanghvi.org//
GATEWAY_INTERFACE = CGI/1.1
HTTP_ACCEPT = text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
HTTP_ACCEPT_CHARSET = ISO-8859-1,utf-8;q=0.7,*;q=0.7
HTTP_ACCEPT_ENCODING = gzip,deflate
HTTP_ACCEPT_LANGUAGE = en
HTTP_CONNECTION = keep-alive
HTTP_HOST = www.sanghvi.org
HTTP_KEEP_ALIVE = 300
HTTP_USER_AGENT = Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.5) Gecko Galeon/2.0.6 (Debian 2.0.6-2+b1)
REDIRECT_STATUS = 200
REMOTE_ADDR = ::ffff:192.168.70.20
REMOTE_PORT = 54879
REQUEST_METHOD = GET
REQUEST_URI = /~mehul/test-cgi.pl
SCRIPT_FILENAME = /home/mehul/public_html/test-cgi.pl
SCRIPT_NAME = /~mehul/test-cgi.pl
SERVER_ADDR = ::
SERVER_NAME = www.sanghvi.org
SERVER_PORT = 80
SERVER_PROTOCOL = HTTP/1.1
SERVER_SOFTWARE = lighttpd/1.4.19
===== END PERL OUTPUT =====


===== SMALLTALK SCRIPT ====
Transcript showCr: 'Content-type: text/html'; nl .
'' displayNl .
'<HTML>' displayNl .
'<HEAD><TITLE>Testing CGI/Smalltalk</TITLE></HEAD>' displayNl .
'<BODY>' displayNl .
'<H2>Yo! Smalltalk,  Whats up ? </H2>' displayNl .

Transcript nl ; showCr: '==== All Env Vars below ====== <br>'; nl.
pipe := FileStream popen: ('set', logFile) dir: FileStream read .
Transcript showCr: pipe contents .

'</BODY>' displayNl .
'</HTML>' displayNl .
======== END SMALLTALK SCRIPT =======


======= SMALLTALK OUTPUT =======


Yo! Smalltalk, Whats up ?
==== All Env Vars below ======
BASH=/bin/sh BASH_ARGC=() BASH_ARGV=() BASH_EXECUTION_STRING=set BASH_LINENO=() BASH_SOURCE=() BASH_VERSINFO=([0]="3" [1]="2" [2]="39" [3]="1" [4]="release" [5]="powerpc-unknown-linux-gnu") BASH_VERSION='3.2.39(1)-release' CONTENT_LENGTH=0 DIRSTACK=() DOCUMENT_ROOT=/var/www/www.sanghvi.org// EUID=33 GATEWAY_INTERFACE=CGI/1.1 GROUPS=() HOSTNAME=tatooine HOSTTYPE=powerpc HTTP_ACCEPT='text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' HTTP_ACCEPT_CHARSET='ISO-8859-1,utf-8;q=0.7,*;q=0.7' HTTP_ACCEPT_ENCODING=gzip,deflate HTTP_ACCEPT_LANGUAGE=en HTTP_CACHE_CONTROL=max-age=0 HTTP_CONNECTION=keep-alive HTTP_HOST=www.sanghvi.org HTTP_KEEP_ALIVE=300 HTTP_USER_AGENT='Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.5) Gecko Galeon/2.0.6 (Debian 2.0.6-2+b1)' IFS=' ' MACHTYPE=powerpc-unknown-linux-gnu OPTERR=1 OPTIND=1 OSTYPE=linux-gnu PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin POSIXLY_CORRECT=y PPID=8315 PS4='+ ' PWD=/home/mehul/public_html REDIRECT_STATUS=200 REMOTE_ADDR=::ffff:192.168.70.20 REMOTE_PORT=50171 REQUEST_METHOD=GET REQUEST_URI=/~mehul/test-cgi.st SCRIPT_FILENAME=/home/mehul/public_html/test-cgi.st SCRIPT_NAME=/~mehul/test-cgi.st SERVER_ADDR=:: SERVER_NAME=www.sanghvi.org SERVER_PORT=80 SERVER_PROTOCOL=HTTP/1.1 SERVER_SOFTWARE=lighttpd/1.4.19 SHELL=/bin/sh SHELLOPTS=braceexpand:hashall:interactive-comments:posix SHLVL=1 TERM=dumb UID=33 _=sh

=======  END SMALLTALK SCRIPT ====


There are extra shell variables showing up like PATH, BASH, TERM, etc. which do not show up in a CGI environment using any other language that I've used to write a similar CGI program (Perl, PHP, Lisp, Scheme, C, Tcl). All of them print out the same variables as the output of the Perl script. What we seem to be doing in Smalltalk is forking/execing a shell and and then getting the environment variables so that we end up with variables from a hybrid environment of CGI and shell.

My platform is also Linux (Debian Testing).

cheers,

    mehul




reply via email to

[Prev in Thread] Current Thread [Next in Thread]