Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to run another program from within a CGI script

Status
Not open for further replies.

new2cgiperl

Programmer
Nov 25, 2007
2
US
hi,

i'm trying to write a CGI script in perl. in the script i execute another command and capture its output using the backticks as follows:

my @list = `myprogram arg1 arg2`;

i then iterate over the list with a for loop and basically print it out in html so it can be viewed from a browser.

to verify i did this correctly, i ran "perl -w myCgiScript.cgi" which generates the HTML on the unix command line and i have verified that the generated HTML is correct, because first of all, it contains the proper output of the list i am iterating on, and secondly, i copied this generated HTML into a brand new file, and opened it up in IE, and the results are as expected - my list gets displayed on the UI.

However, when I try to reach my CGI script directly with a URL from the IE, I get everything except my list. It is just blank where the list should be. Any ideas as to where I may be going wrong will be helpful. Thanks!
 
put full paths to everything in the system call and verify that it actually works when ran as the user that the httpd is running as (normally something).

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Travis,

Thanks for your help, I tried adding full paths and made sure that my files are world readable and executable.

On the command line, when I do a "perl -w myCgiScript.cgi" my output HTML is correct, just like before.

On the browser though, I now get a "bad file unit number" for my program file...
 
Does your script also have paths to files and such that need a full path?

if you script is in /var/ (for example) try it running it from /home/user/ by typing in the full path to the script (/var/ But you may have things in your path that don't exist in path (if that's who your webserver is running as). Make sure your other script has absolute paths to everything (not ../blah/blah but /path/to/the/real/file). This is a very common thing that happens to everyone when they first start getting into web based scripts :)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top