Computing.Net > Forums > Linux > Printing a command's output (CGI)

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Printing a command's output (CGI)

Reply to Message Icon

Name: Edwards
Date: April 18, 2003 at 19:10:54 Pacific
OS: Red Hat 8.0
CPU/Ram: PII-350/256MB
Comment:

I want a script that'll print the output of a certain command (fortune homer). I can't get the script to print the output, and I'm not sure if it's being run at all. My more recent attempts end with this wonderful error:
(in error_log) Premature end of script headers: homer.cgi
(in access_log) "GET /cgi-bin/homer.cgi HTTP/1.1" 500 656

So, how do I do this?



Sponsored Link
Ads by Google

Response Number 1
Name: Dlonra
Date: April 19, 2003 at 16:17:31 Pacific
Reply:

what do you get with
./homer.cgi?

google
cgi tutorial


0

Response Number 2
Name: Edwards
Date: April 19, 2003 at 19:57:12 Pacific
Reply:

When I run homer.cgi, I get a 500 Internal Server Error... more info available in the log. I've googled, but haven't found anything about running commands and printing their output. The closest I've found is printing a line from a file.


0

Response Number 3
Name: Edwards
Date: April 19, 2003 at 20:11:40 Pacific
Reply:

It works! I modified a ping script I found so that instead of running ping $dest, it runs fortune $file (where $file is defined within the script as homer), and IT WORKS!

I wonder if I can mod it so that $file can be defined in the URL...?


0

Response Number 4
Name: 3Dave
Date: April 22, 2003 at 06:37:25 Pacific
Reply:

Not sure what language you are using, but in perl:
print "$variable";
output: value
print '$variable';
output: $variable
print `uname -o`;
output: GNU/Linux

Notice the three different quotes ( " ' ` ), for normal use, literal printing (ie doesn't evaluate variables etc) and te last for printing commands to the operating system. If the command produces an output to stdout, it is returned and printed.

It is often useful to enclose these command outputs within html {pre} and {/pre} tags which keep the formatting of the text.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Linux Forum Home


Sponsored links

Ads by Google


Results for: Printing a command's output (CGI)

awk and substr www.computing.net/answers/linux/awk-and-substr/29840.html

diff command www.computing.net/answers/linux/diff-command-/26752.html

successfully complete a command www.computing.net/answers/linux/successfully-complete-a-command/20085.html