Simon336697
asked on
Perl script - output to display via PHP in a browser
Hi guys!
I have the following Perl script that works fine.
What Id like to do with it is:
By utilizing my current perl code, use PHP to:
1) Build a form somehow where I could manually enter the name of the computer system list (instead of hard coding into my script..currently set to list.xt)
2) Click a Run button to execute the script
3) Write the output to a browser window, maybe in a 3 column window, eg. 1 for notexist.txt, 1 for olderthan2.txt", the other for recent.txt Here is the perl code:
-------------------------- ---------- ---------- ---------- ---------- ---------- ------- script.pl
#!/usr/bin/perl -w
use strict;
use warnings;
open(NOTEXIST, ">notexist.txt") or die "Can not create notexist: $!\n";
open(OLD, ">olderthan2.txt") or die "Can not create olderthan2: $!\n";
open(RECENT, ">recent.txt") or die "Can not create recent: $!\n";
open(LIST,"<list.txt") or die "Can not open list: $!\n";
while (my $server=<LIST>) {
system("net use s: \\$server\ipc\$");
if(!-e 's:\password.txt') {
print NOTEXIST "$server doesnt exist\n";
}
elsif(-M 's:\password.txt' > 2) {
print OLD "$server " . localtime( (stat('s:\password.txt'))[ 9] ) . "\n";
}
else {
print RECENT "$server " . localtime( (stat('s:\password.txt'))[ 9] ) . "\n";
}
}
close(LIST);
close(RECENT);
close(OLD);
close(NOTEXIST);
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- -------- End of script.
So, in the above, instead of displaying the results in:
open(NOTEXIST, ">notexist.txt") or die "Can not create notexist: $!\n";
open(OLD, ">olderthan2.txt") or die "Can not create olderthan2: $!\n";
open(RECENT, ">recent.txt") or die "Can not create recent: $!\n";
the results could appear in a browser.
Any help greatly appreciated.
I have the following Perl script that works fine.
What Id like to do with it is:
By utilizing my current perl code, use PHP to:
1) Build a form somehow where I could manually enter the name of the computer system list (instead of hard coding into my script..currently set to list.xt)
2) Click a Run button to execute the script
3) Write the output to a browser window, maybe in a 3 column window, eg. 1 for notexist.txt, 1 for olderthan2.txt", the other for recent.txt Here is the perl code:
--------------------------
#!/usr/bin/perl -w
use strict;
use warnings;
open(NOTEXIST, ">notexist.txt") or die "Can not create notexist: $!\n";
open(OLD, ">olderthan2.txt") or die "Can not create olderthan2: $!\n";
open(RECENT, ">recent.txt") or die "Can not create recent: $!\n";
open(LIST,"<list.txt") or die "Can not open list: $!\n";
while (my $server=<LIST>) {
system("net use s: \\$server\ipc\$");
if(!-e 's:\password.txt') {
print NOTEXIST "$server doesnt exist\n";
}
elsif(-M 's:\password.txt' > 2) {
print OLD "$server " . localtime( (stat('s:\password.txt'))[
}
else {
print RECENT "$server " . localtime( (stat('s:\password.txt'))[
}
}
close(LIST);
close(RECENT);
close(OLD);
close(NOTEXIST);
--------------------------
So, in the above, instead of displaying the results in:
open(NOTEXIST, ">notexist.txt") or die "Can not create notexist: $!\n";
open(OLD, ">olderthan2.txt") or die "Can not create olderthan2: $!\n";
open(RECENT, ">recent.txt") or die "Can not create recent: $!\n";
the results could appear in a browser.
Any help greatly appreciated.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Why not do it all in Perl?
ASKER
Hi mj!
Can you do this all in Perl mjcoyne! And display it in a browser?
Can you do this all in Perl mjcoyne! And display it in a browser?
ASKER
Would you typically use the LWP module for this?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Perl Diver...
Thank u so much for your help.
I ran your code, but not getting any success.
-------------------------- ---------- ---------- ---------- ---------- --
#!/usr/bin/perl
use strict;
use warnings;
use CGI qw/:standard/;
print header, start_html(-title=>'your webpage title');
#open(NOTEXIST, ">notexist.txt") or die "Can not create notexist: $!\n";
#open(OLD, ">olderthan2.txt") or die "Can not create olderthan2: $!\n";
#open(RECENT, ">recent.txt") or die "Can not create recent: $!\n";
open(LIST,"<c:\\dood\\list .txt") or die "Can not open list: $!\n";
while (my $server=<LIST>) {
chomp($server);
# system("net use s: \\$server\\pass\$ \"password\" /user:$server\\administrat or > NUL");
system("net use s: \\$server\\pass\$");
if(!-e 's:\password.txt') {
print "$server doesnt exist<br/>\n";
}
elsif(-M 's:\password.txt' > 2) {
print "$server " . localtime( (stat('s:\password.txt'))[ 9] ) . "<br/>\n";
}
else {
print "$server " . localtime( (stat('s:\password.txt'))[ 9] ) . "<br/>\n";
}
}
close(LIST);
#close(RECENT);
#close(OLD);
#close(NOTEXIST);
print end_html;
-------------------------- ---------- ---------- ---- Output:
C:\dood>nn.pl
Content-Type: text/html; charset=ISO-8859-1
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"><head><title> your webpa
e title</title>
</head><body>System error 67 has occurred.
The network name cannot be found.
predator doesnt exist<br/>
</body></html>
C:\dood>
========================== ========== ========== ======
predator is the name of my local machine, and the only entry in list.txt
If i do a net use s: \\predator\pass$,
I get a connection no problems.
Thank u so much for your help.
I ran your code, but not getting any success.
--------------------------
#!/usr/bin/perl
use strict;
use warnings;
use CGI qw/:standard/;
print header, start_html(-title=>'your webpage title');
#open(NOTEXIST, ">notexist.txt") or die "Can not create notexist: $!\n";
#open(OLD, ">olderthan2.txt") or die "Can not create olderthan2: $!\n";
#open(RECENT, ">recent.txt") or die "Can not create recent: $!\n";
open(LIST,"<c:\\dood\\list
while (my $server=<LIST>) {
chomp($server);
# system("net use s: \\$server\\pass\$ \"password\" /user:$server\\administrat
system("net use s: \\$server\\pass\$");
if(!-e 's:\password.txt') {
print "$server doesnt exist<br/>\n";
}
elsif(-M 's:\password.txt' > 2) {
print "$server " . localtime( (stat('s:\password.txt'))[
}
else {
print "$server " . localtime( (stat('s:\password.txt'))[
}
}
close(LIST);
#close(RECENT);
#close(OLD);
#close(NOTEXIST);
print end_html;
--------------------------
C:\dood>nn.pl
Content-Type: text/html; charset=ISO-8859-1
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"><head><title>
e title</title>
</head><body>System error 67 has occurred.
The network name cannot be found.
predator doesnt exist<br/>
</body></html>
C:\dood>
==========================
predator is the name of my local machine, and the only entry in list.txt
If i do a net use s: \\predator\pass$,
I get a connection no problems.
ASKER
I changed the code to:
#!/usr/bin/perl
use strict;
use warnings;
use CGI qw/:standard/;
print header, start_html(-title=>'your webpage title');
#open(NOTEXIST, ">notexist.txt") or die "Can not create notexist: $!\n";
#open(OLD, ">olderthan2.txt") or die "Can not create olderthan2: $!\n";
#open(RECENT, ">recent.txt") or die "Can not create recent: $!\n";
open(LIST,"<c:\\dood\\list .txt") or die "Can not open list: $!\n";
while (my $server=<LIST>) {
chomp(my $server);
# system("net use s: \\my $server\\pass\$ \"password\" /user:$server\\administrat or > NUL");
system("net use s: \\my $server\\pass\$");
if(!-e 's:\password.txt') {
print "my $server doesnt exist<br/>\n";
}
elsif(-M 's:\password.txt' > 2) {
print "my $server " . localtime( (stat('s:\password.txt'))[ 9] ) . "<br/>\n";
}
else {
print "my $server " . localtime( (stat('s:\password.txt'))[ 9] ) . "<br/>\n";
}
}
close(LIST);
#close(RECENT);
#close(OLD);
#close(NOTEXIST);
print end_html;
========================== ========== == Output:
C:\dood>nn.pl
Content-Type: text/html; charset=ISO-8859-1
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"><head><title> your webpag
e title</title>
Use of uninitialized value in scalar chomp at C:\dood\nn.pl line 14, <LIST> line
1.
Use of uninitialized value in concatenation (.) or string at C:\dood\nn.pl line
16, <LIST> line 1.
</head><body>System error 67 has occurred.
The network name cannot be found.
Use of uninitialized value in concatenation (.) or string at C:\dood\nn.pl line
18, <LIST> line 1.
my doesnt exist<br/>
</body></html>
C:\dood>
#!/usr/bin/perl
use strict;
use warnings;
use CGI qw/:standard/;
print header, start_html(-title=>'your webpage title');
#open(NOTEXIST, ">notexist.txt") or die "Can not create notexist: $!\n";
#open(OLD, ">olderthan2.txt") or die "Can not create olderthan2: $!\n";
#open(RECENT, ">recent.txt") or die "Can not create recent: $!\n";
open(LIST,"<c:\\dood\\list
while (my $server=<LIST>) {
chomp(my $server);
# system("net use s: \\my $server\\pass\$ \"password\" /user:$server\\administrat
system("net use s: \\my $server\\pass\$");
if(!-e 's:\password.txt') {
print "my $server doesnt exist<br/>\n";
}
elsif(-M 's:\password.txt' > 2) {
print "my $server " . localtime( (stat('s:\password.txt'))[
}
else {
print "my $server " . localtime( (stat('s:\password.txt'))[
}
}
close(LIST);
#close(RECENT);
#close(OLD);
#close(NOTEXIST);
print end_html;
==========================
C:\dood>nn.pl
Content-Type: text/html; charset=ISO-8859-1
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"><head><title>
e title</title>
Use of uninitialized value in scalar chomp at C:\dood\nn.pl line 14, <LIST> line
1.
Use of uninitialized value in concatenation (.) or string at C:\dood\nn.pl line
16, <LIST> line 1.
</head><body>System error 67 has occurred.
The network name cannot be found.
Use of uninitialized value in concatenation (.) or string at C:\dood\nn.pl line
18, <LIST> line 1.
my doesnt exist<br/>
</body></html>
C:\dood>
With the first example, try this for your system command:
system("net use s: \\\\$server\\pass\$");
system("net use s: \\\\$server\\pass\$");
Well, this is wrong:
while (my $server=<LIST>) {
chomp(my $server);
you can't use "my" twice on the scalar $server in the same scope otherwise $server will have no value, hench the warnings about an undefined value in chomp and concatenation. Should be like I had it:
while (my $server = <LIST>) {
chomp($server);
is it possible there are blank lines in the file you are looping through? Also try Adams suggestion about properly escaping the backslashes in the system function argument.
while (my $server=<LIST>) {
chomp(my $server);
you can't use "my" twice on the scalar $server in the same scope otherwise $server will have no value, hench the warnings about an undefined value in chomp and concatenation. Should be like I had it:
while (my $server = <LIST>) {
chomp($server);
is it possible there are blank lines in the file you are looping through? Also try Adams suggestion about properly escaping the backslashes in the system function argument.
I see you have "my" in the print lines too. They will not affect the script as they are treated as the literal string "my" and not the function "my" but you only use "my" once to decalre a variable within a block of code.
http://perldoc.perl.org/functions/my.html
http://perldoc.perl.org/functions/my.html
ASKER
========================== ========== ========== ========== ==== nn.pl
#!/usr/bin/perl
use strict;
use warnings;
use CGI qw/:standard/;
print header, start_html(-title=>'your webpage title');
open(LIST,"<list.txt") or die "Can not open list: $!\n";
while (my $server=<LIST>) {
chomp($server);
system("net use s: \\$server\\pass\$");
if(!-e 's:\password.txt') {
print "$server doesnt exist<br/>\n";
}
elsif(-M 's:\password.txt' > 2) {
print "$server " . localtime( (stat('s:\password.txt'))[ 9] ) . "<br/>\n";
}
else {
print "$server " . localtime( (stat('s:\password.txt'))[ 9] ) . "<br/>\n";
}
}
close(LIST);
print end_html;
========================== ========== ========== ========== ======= Output
C:\>nn.pl
Content-Type: text/html; charset=ISO-8859-1
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"><head><title> your webpag
e title</title>
</head><body>System error 67 has occurred.
The network name cannot be found.
predator doesnt exist<br/>
</body></html>
C:\>
========================== ========== ========== =========
If I separately do a net use s:, its fine.
#!/usr/bin/perl
use strict;
use warnings;
use CGI qw/:standard/;
print header, start_html(-title=>'your webpage title');
open(LIST,"<list.txt") or die "Can not open list: $!\n";
while (my $server=<LIST>) {
chomp($server);
system("net use s: \\$server\\pass\$");
if(!-e 's:\password.txt') {
print "$server doesnt exist<br/>\n";
}
elsif(-M 's:\password.txt' > 2) {
print "$server " . localtime( (stat('s:\password.txt'))[
}
else {
print "$server " . localtime( (stat('s:\password.txt'))[
}
}
close(LIST);
print end_html;
==========================
C:\>nn.pl
Content-Type: text/html; charset=ISO-8859-1
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"><head><title>
e title</title>
</head><body>System error 67 has occurred.
The network name cannot be found.
predator doesnt exist<br/>
</body></html>
C:\>
==========================
If I separately do a net use s:, its fine.
ASKER
Ok it looked like it was because i had:
\\$server
instead of
\\\\$server
-------------------------- --Output now is:
C:\>nn.pl
Content-Type: text/html; charset=ISO-8859-1
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"><head><title> your webpag
e title</title>
</head><body>predator Mon Jul 30 13:02:42 2007<br/>
</body></html>
C:\>
-------------------------- ---------- ---------- ----
But a web page is not created.
\\$server
instead of
\\\\$server
--------------------------
C:\>nn.pl
Content-Type: text/html; charset=ISO-8859-1
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"><head><title>
e title</title>
</head><body>predator Mon Jul 30 13:02:42 2007<br/>
</body></html>
C:\>
--------------------------
But a web page is not created.
The script is intended to be run from a webserver. When a browser calls the script, it will be displayed in the browser.
Is this not what you wanted?
If you redirect the output to a .html file, you can then open that with a browser (you'll probably want to remove the header first though).
eg:
at a prompt, type: nn.pl > test1.html
edit test1.html using a text editor, remove the "Content-Type" line, and the blank line, save file
Use web browser to view test1.html (at prompt, type "test1.html", but no quotes)
Is this not what you wanted?
If you redirect the output to a .html file, you can then open that with a browser (you'll probably want to remove the header first though).
eg:
at a prompt, type: nn.pl > test1.html
edit test1.html using a text editor, remove the "Content-Type" line, and the blank line, save file
Use web browser to view test1.html (at prompt, type "test1.html", but no quotes)
ASKER
Hi Adam!
Yes youre right, it is what I wanted to be shown in a web browser.
http://localhost/nn.pl
It just comes up with a File Save/Open dialog.
When I click on Open, it just displays the code in the browser.
Yes youre right, it is what I wanted to be shown in a web browser.
http://localhost/nn.pl
It just comes up with a File Save/Open dialog.
When I click on Open, it just displays the code in the browser.
ASKER
Im my Perl libs:
C:\Perl\lib\CGI
Volume in drive C has no label.
Volume Serial Number is 74DC-C9FB
Directory of c:\perl\lib\cgi
16/07/2007 09:08 AM <DIR> .
16/07/2007 09:08 AM <DIR> ..
19/06/2002 09:26 PM 297 Apache.pm
14/07/2002 07:23 AM 13,112 Carp.pm
19/06/2002 09:26 PM 13,658 Cookie.pm
16/07/2007 09:08 AM <DIR> eg
19/06/2002 09:26 PM 7,423 Fast.pm
19/06/2002 09:26 PM 7,262 Pretty.pm
21/03/2001 11:31 AM 11,267 Push.pm
19/06/2002 09:26 PM 312 Switch.pm
19/06/2002 09:26 PM 11,039 Util.pm
8 File(s) 64,370 bytes
3 Dir(s) 235,949,752,320 bytes free
C:\Perl\lib\CGI
Volume in drive C has no label.
Volume Serial Number is 74DC-C9FB
Directory of c:\perl\lib\cgi
16/07/2007 09:08 AM <DIR> .
16/07/2007 09:08 AM <DIR> ..
19/06/2002 09:26 PM 297 Apache.pm
14/07/2002 07:23 AM 13,112 Carp.pm
19/06/2002 09:26 PM 13,658 Cookie.pm
16/07/2007 09:08 AM <DIR> eg
19/06/2002 09:26 PM 7,423 Fast.pm
19/06/2002 09:26 PM 7,262 Pretty.pm
21/03/2001 11:31 AM 11,267 Push.pm
19/06/2002 09:26 PM 312 Switch.pm
19/06/2002 09:26 PM 11,039 Util.pm
8 File(s) 64,370 bytes
3 Dir(s) 235,949,752,320 bytes free
ASKER
If I do:
nn.pl > test1.html
and open test1.html in a browser:
-------------------------- ---------- ---------- ---- output
Content-Type: text/html; charset=ISO-8859-1 predator Mon Jul 30 13:02:42 2007
-------------------------- ---------- ---------- ---
Could it be because of the header in my code, or lack of header?
-------------------------- ---------- ---------- ---------- - nn.pl
#!/usr/bin/perl
use strict;
use warnings;
use CGI qw/:standard/;
print header, start_html(-title=>'your webpage title');
open(LIST,"<list.txt") or die "Can not open list: $!\n";
while (my $server=<LIST>) {
chomp($server);
system("net use s: \\\\$server\\pass\$ > NUL");
if(!-e 's:\password.txt') {
print "$server doesnt exist<br/>\n";
}
elsif(-M 's:\password.txt' > 2) {
print "$server " . localtime( (stat('s:\password.txt'))[ 9] ) . "<br/>\n";
}
else {
print "$server " . localtime( (stat('s:\password.txt'))[ 9] ) . "<br/>\n";
}
}
close(LIST);
print end_html;
-------------------------- --------
nn.pl > test1.html
and open test1.html in a browser:
--------------------------
Content-Type: text/html; charset=ISO-8859-1 predator Mon Jul 30 13:02:42 2007
--------------------------
Could it be because of the header in my code, or lack of header?
--------------------------
#!/usr/bin/perl
use strict;
use warnings;
use CGI qw/:standard/;
print header, start_html(-title=>'your webpage title');
open(LIST,"<list.txt") or die "Can not open list: $!\n";
while (my $server=<LIST>) {
chomp($server);
system("net use s: \\\\$server\\pass\$ > NUL");
if(!-e 's:\password.txt') {
print "$server doesnt exist<br/>\n";
}
elsif(-M 's:\password.txt' > 2) {
print "$server " . localtime( (stat('s:\password.txt'))[
}
else {
print "$server " . localtime( (stat('s:\password.txt'))[
}
}
close(LIST);
print end_html;
--------------------------
ASKER
http://localhost/nn.pl
It looks like this is being executed, but is at a command line, just not displaying in a browser.
It looks like this is being executed, but is at a command line, just not displaying in a browser.
ASKER
Sorry, NOT being executed it should be.
So, http://localhost/nn.pl is NOT working.
So, http://localhost/nn.pl is NOT working.
It sounds as though your webserver is not configured to execute the script.
Which webserver are you running?
Does it work if you put nn.pl in the cgi-bin subdirectory?
Which webserver are you running?
Does it work if you put nn.pl in the cgi-bin subdirectory?
ASKER
Hi Adam!
c:\wamp\www
The above is the document root.
C:\wamp\Apache2\cgi-bin
This is my cgi-bin folder
Ive been trying to do the following:
http://localhost/nn.pl
and have placed password.txt, nn.pl, and list.txt in c:\wamp\www
If I need to place all these in c:\wamp\Apache2\cgi-bin
then how would I point to nn.pl from my web browser?
c:\wamp\www
The above is the document root.
C:\wamp\Apache2\cgi-bin
This is my cgi-bin folder
Ive been trying to do the following:
http://localhost/nn.pl
and have placed password.txt, nn.pl, and list.txt in c:\wamp\www
If I need to place all these in c:\wamp\Apache2\cgi-bin
then how would I point to nn.pl from my web browser?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Adam...that worked mate thank you...and to everyone.
Just on the same thing quickly...
In the same directory as nn.pl (eg.c:\wamp\apache2\cgi-bi n), there is a demo perl script to print env variables..
The code is:----------------printen v.pl
#!c:/perl/bin/perl.exe
##
## printenv -- demo CGI program which just prints its environment
##
print "Content-type: text/html\n\n";
foreach $var (sort(keys(%ENV))) {
$val = $ENV{$var};
print "${var}=\"${val}\"\n";
}
========================== =========
http://localhost/cgi-bin/printenv.pl gives me........................ .......... .......... .......
COMSPEC="C:\WINDOWS\system 32\cmd.exe " DOCUMENT_ROOT="C:/wamp/www " GATEWAY_INTERFACE="CGI/1.1 " HTTP_ACCEPT="*/*" HTTP_ACCEPT_ENCODING="gzip , deflate" HTTP_ACCEPT_LANGUAGE="en-a u" HTTP_CONNECTION="Keep-Aliv e" HTTP_HOST="localhost" HTTP_UA_CPU="x86" HTTP_USER_AGENT="Mozilla/4 .0 (compatible; MSIE 7.0; Windows NT 5.1)" PATH="C:\Perl\bin\;C:\Prog ram Files\Windows Resource Kits\Tools\;c:\Perl\bin;C: \WINDOWS\s ystem32;C: \WINDOWS;C :\WINDOWS\ System32\W bem;C:\Pro gram Files\IDM Computer Solutions\UltraEdit-32;C:\ Handy;C:\W AMP\;C:\WA MP\MySQL\B in;" PATHEXT=".COM;.EXE;.BAT;.C MD;.VBS;.V BE;.JS;.JS E;.WSF;.WS H" QUERY_STRING="" REMOTE_ADDR="127.0.0.1" REMOTE_PORT="2458" REQUEST_METHOD="GET" REQUEST_URI="/cgi-bin/prin tenv.pl" SCRIPT_FILENAME="C:/wamp/A pache2/cgi -bin/print env.pl" SCRIPT_NAME="/cgi-bin/prin tenv.pl" SERVER_ADDR="127.0.0.1" SERVER_ADMIN="webmaster@lo calhost" SERVER_NAME="localhost" SERVER_PORT="80" SERVER_PROTOCOL="HTTP/1.1" SERVER_SIGNATURE="" SERVER_SOFTWARE="Apache/2. 2.4 (Win32) PHP/5.2.3" SYSTEMROOT="C:\WINDOWS" WINDIR="C:\WINDOWS"
-------------------------- ---------- ---------- ---------- ---------- ---------- --------
Just on the same thing quickly...
In the same directory as nn.pl (eg.c:\wamp\apache2\cgi-bi
The code is:----------------printen
#!c:/perl/bin/perl.exe
##
## printenv -- demo CGI program which just prints its environment
##
print "Content-type: text/html\n\n";
foreach $var (sort(keys(%ENV))) {
$val = $ENV{$var};
print "${var}=\"${val}\"\n";
}
==========================
http://localhost/cgi-bin/printenv.pl gives me........................
COMSPEC="C:\WINDOWS\system
--------------------------
ASKER
Thanks guys.
If you add a <br /> to the print statement, it'll make it easier to read from a webpage:
print "${var}=\"${val}\"<br />\n";
print "${var}=\"${val}\"<br />\n";
ASKER
Thanks Adam!