What is wrong with this CGI script? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

What is wrong with this CGI script?

Can you find anything wrong? It is run on a UNIX server:

#
# shows who is logged on to the server
#

#!/usr/bin/perl
use CGI::Carp qw(fatalsToBrowser);
print "Content-type: text/html

";
my $who_cmd = 'bin/who';
my &who = `$who_cmd`;
print
Who is on the server

Who is on the server



$who


EOM
exit;

Comments

  • LKATSCHLKATSCH Posts: 1Member
    : Can you find anything wrong? It is run on a UNIX server:
    :
    : #
    : # shows who is logged on to the server
    : #
    :
    : #!/usr/bin/perl
    : use CGI::Carp qw(fatalsToBrowser);
    : print "Content-type: text/html

    ";
    : my $who_cmd = 'bin/who';
    : my &who = `$who_cmd`;
    : print <<EOM;
    : <HTML>
    : Who is on the server
    :
    :

    Who is on the server

    :

    :
    : $who
    :

    :
    :
    :
    : EOM
    : exit;
    :
    Try an ; after the mark EOM ...
    :-)
  • : #
    : # shows who is logged on to the server
    : #
    :
    : #!/usr/bin/perl
    : use CGI::Carp qw(fatalsToBrowser);
    : print "Content-type: text/html

    ";
    : my $who_cmd = `/bin/who`;
    : my $who = `$who_cmd`;
    : print <<EOM;
    : <HTML>
    : Who is on the server
    :
    :

    Who is on the server

    :

    :
    : $who
    :

    :
    :
    :
    : EOM
    : exit;
    :

    On line 3, you had "bin/who" which will look in the current directory, i changed it to "/bin/who" to search from the root directory. Also on line 4 to execute a command use backticks (``) not single quotes (''), the backtick is under escape. And finally also on line 4 there was &who = ... which is making a subroutine, not a scalar, changed that 2 :)

    should now have no probs running...hopefully
Sign In or Register to comment.