Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Single quoted command. OK in test, fails in CGI

Posted by enquirer (enquirer), 3 November 2004
I am attempting to write some perl using the perl cgi.pm module.   I cannot get it to display string variable values on a web page. I can only display text that I type explicitly.

For example, in the code below, The output to the screen is:
     HELLOHELLO THERE!!!How are youu ''

Notice that it places the '' as concatenated with $temp, but does print the value of $temp as well.

     Can you help me

Code:
use CGI;

     my ($query) =  new CGI ;
     my (@data) = ();
     my ($temp) = ();

     @data = `getproj_2`;        #@data is now an array of sentences (strings)
     $temp = $data[2];
     chomp $temp;
     $temp = "'".$temp."'";

     print $query->header(),
     $query->start_html(-title=>"getproj CGI",
            -author=>"Pxxx Dxxxx"),
     $query->center($query->h1('This is the heading')),

     $query->b($query->i($query->center('This is the sub-heading<BR><BR><BR>'))),
     'HELLO',
     'HELLO THERE!!!',
     "How are you $temp???",

     $query->end_html();


Posted by admin (Graham Ellis), 3 November 2004
I had a bit of "fun" with that too.  

Turned out to be the path to getproj_2 / permissions on it.

Although you probably tested the script under your user account (and so with your permissions and your path), when run by the web server it's run with the permissisons and environment of that server, which are probably different.   I persuaded it to functions by checking that there were permissions for getproj_2 to execute as the server and by specifying a complete path to it.    Here's the code I ended up with:

Code:
#!/usr/bin/perl

use CGI;

my ($query) = new CGI ;
my (@data) = ();
my ($temp) = ();

@data = `/Library/WebServer/live_cgi-bin/demo/getproj_2`;
$temp = $data[2];
chomp $temp;
$temp = "'".$temp."'";

print $query->header(),
$query->start_html(-title=>"getproj CGI",
        -author=>"Pxxx Dxxxx"),
$query->center($query->h1('This is the heading')),

$query->b($query->i($query->center('This is the sub-heading<BR><BR><BR>'))),
'HELLO',
'HELLO THERE!!!',
"How are you $temp???",

$query->end_html();


and I had the following in getproj_2 ...

Code:
#!/usr/bin/perl

print <<END
This is the month of the year
When Autum comes - but be of good cheer.
The leaves to fall the wind doth blow
But at least it isn't the season of Snow
END



Posted by admin (Graham Ellis), 3 November 2004
(This follow up later ... in case the above solution didn't work)

I took my (working) example and moved getproj_2 into a subdirectory and it worked fine. I then changed the permissions on that subdirectory to "700" and it worked fine in debug mode and failed in "live" mode just as you described. Changed it back to 755 again, worked again.

You might also like to check the $? variable after the call - it's returns the status of the command run in backtics and you should get 0 if it suceeds and a code (I get -1) if it failed to run ... in the case just above due to permissions.

Finally, you it might be worth you looking in your getproj_2 to see if it uses environment variables and / or the "-t" operator on STDIN or STDOUT to see if they're interactive devices.  



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho