Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.