For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > February 2005 > printing output of a command









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author printing output of a command
TapasranjanMohapatra

2005-02-21, 3:56 am

All,
i am new to cgi. Please let me know why I dont get the data printed?
I have abc.cgi in /var/www/cgi-bin

When the $cmd is "ls" I get the filenames when I visit =
localhost/cgi-bin/abc.cgi
But when the $cmd is the snmpquerry, I get nothing on the page, though I =
get the desired output(value of sysContact.0) when I run the script in =
commandline.

----------------------------
#! /usr/bin/perl
print "Content-type: text/html\n\n";
print <<"END OF PRINT";
<html>
<head><title>test</title></head>
<body>
END OF PRINT
my $cmd =3D "snmpget 23.23.23.23 public sysContact.0";
#my $cmd =3D "ls";
my $res =3D qx!$cmd!;
chomp($res);
print <<"end of print";
<center>
$res
</center>
</body></html>
end of print
-------------------------------------

TIA
Tapas
Mark Rogaski

2005-02-21, 3:56 am

TapasranjanMohapatra <TapasranjanMohapatra@infosys.com> wrote:
>
> my $cmd = "snmpget 23.23.23.23 public sysContact.0";
> #my $cmd = "ls";
> my $res = qx!$cmd!;
> chomp($res);
> print <<"end of print";
> <center>
> $res
> </center>
> </body></html>
> end of print


It's possible that the command is returning an error ... the snmpget
command may not be in the path specified by the PATH environment varible
that is passed by the CGI. Any output to standard error will not end up
in $res.

Make sure to use an absolute path for the command (eg.
/usr/local/bin/snmpget) or make sure that $ENV{PATH} contains the
location of the executable. Also, make sure to check the $? variable to
make sure that the command did complete successfully.

On a final note, you might want to look into using Net::SNMP.

Mark

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com