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
 
This week, we're updating our course layouts and descriptions. Presentation and materials always gently change over time, but just occasionally there's a need to make a step change to clear out some of the old and roll in the new. That's now happening - but over a long and complex site it's not instant and you'll see sections of the site changing up to and including 19th September.

See also [here] for status update
 
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., 2014: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho