Question:
Perl does not execute system() function when called from HTML?
Prabhnoor Kainth
2012-06-23 16:23:18 UTC
When I manually run a perl script from Command Prompt, the system("java pan") command and rest of the script is properly executed but when the same script is called from html page, the script does get properly executed except the system("java pan") function. What can be the problem?
Four answers:
Studio XYZ
2012-06-23 16:39:17 UTC
When executed from an html page, or by the web server, the script is being executed as a different user than when you run the script from the command line. In this case the web server user is running the script. Because of this you may need to provide the full path to "java". I don't know where java exists on the system but your command may need to look something like this:



system("/usr/bin/java pan");



----



I'm running Apache web server and, yes, you can make "system" calls inside a CGI script. Even PHP provides the shell_exec() function. That does not mean that you don't have to be careful doing so. With careless programming, you can open yourself up to big problems. Server configurations vary, of course, and some may restrict cgi completely.



I tested a small perl script to verify that the results of a shell command can be captured and displayed on a web page. This is the script:





#!/usr/bin/perl



@result = `echo "Hello from the command line!"`;



print "Content-type: text/html\r\n\r\n";

print "
    \n";

    for(@result) {

    chomp($_);

    print "
  • $_
  • \n";

    }

    print "
\n";



This script uses the backtick (`) operator instead of the system() function to execute the call because it makes capturing the results easier. @result is used in array context in case multiple lines are returned. This script outputs the following:





Content-type: text/html









  • Hello from the command line!








I called the script using Safari web browser and the page displayed as expected.



I hope this helps!
Dubist Arschlock
2012-06-24 01:18:30 UTC
Web servers won't run "system" calls inside CGI scripts, because it's a huge security hole, and even an inexperienced hacker can use it to hijack your computer.



Try using the "Taint switch" ( -T ) (Google it) and if it gives you an error, you'll need to wrap the Java call in another function that isn't directly on the page, best of all, convert your Java program to Perl.
hellen
2016-07-22 04:24:50 UTC
Personal home page functions best work by means of php documents. If it is a php file then simply add that code wherever you want it to work its stuff. You don't must do any certain HTML tags to call a php tag - php tags are introduced into motion as soon as the server notices it.
anonymous
2012-06-23 16:23:52 UTC
Perl isn't installed correctly.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...