me1 has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I have this code which I am using to try and run the program called a1, but it does not seem to be working. Does anyone know how to run programs using perl or cgi or use command line language in perl or cgi. Thanks!

#!/usr/bin/perl -w use CGI; $query = new CGI; # Tell perl to send a html header. # So your browser gets the output # rather then <stdout>(command line # on the server.) print "Content-type: text/html\n\n"; # print your basic html tags. # and the content of them. print "<html><head><title>Hello World!! </title>"; print "</head>\n"; print "<body><h1>Hello world</h1>"; print "</body>"; print "</html>\n"; my $prgm = system ('ssh root\@1\.1\.1\.1\executable1\a1'); if ($? == -1) { print "Command Failed: $!\n"; } else { print "Command exited with value %d", $? >>8; } print $prgm;

PS: The name of the folder is supposed to be executable1 and the a1 is the actual executable program.

Replies are listed 'Best First'.
Re: executing a program
by choroba (Cardinal) on Jul 12, 2011 at 11:46 UTC
    Why do you quote the at-sign and dots inside single quotes? If you want ssh to run a program, separate the hostname from the path by a space.
    Using ssh root@... in a CGI application sounds like a security risk.
    For printing headers in CGI, it's better to use the header() function.
Re: executing a program
by amcglinchy (Novice) on Jul 12, 2011 at 17:06 UTC

    In addition to the previous monk's suggestions I recommend reviewing the documentation for system . I don't think you want the final print to do what it does.

    I also concur with the other monks' wisdom regarding the foolhardy use of 'ssh root@...'

Re: executing a program
by i5513 (Pilgrim) on Jul 12, 2011 at 14:27 UTC

    Test first the system call. When it work, go ahead with CGI (but it could be a security issue like other monk told you).

    Why are you writting first <html>..</html> code ?

    See CGI and see start_html, end_html to not have to writting raw html (or use Here Documents)