PDA

View Full Version : Running another program using cgi


kevygee
08-04-2004, 05:24 PM
I have this cgi script that gets called when a button is clicked on an html form. One of the first things the script is supposed to do is run a program, located in the same directory. So, for example, I wrote a hello world program in C, compiled it and now have an executable in my cgi-bin directory. And in my cgi script I have the lines
open(PROG, "helloWorld") or die "Yada yada $!";
while(<PROG>) {
$output.=$_;
}

So this works that it can catch output from the call, but it gives me a permissions denied error. I'm not sure where the permissions would be wrong because the executable is set at 755 and in the same directory as the actual program. Is there something I"m not thinking of here? Any ideas?

MattJakel
08-05-2004, 06:58 AM
output.=$_;


I don't understand how this line would work at all... it seems that output would need to be a variable in this case, so it would have to be $output. Other than that, I don't know anything about running other programs from Perl, so I couldn't help you.

Matt

kevygee
08-05-2004, 04:11 PM
That was a typo. Fixed now.

kevygee
08-09-2004, 06:24 PM
I've come up with a way to solve the problem, so I thought I would post it to let people know. Since the program that I wanted to run was a compiled c program, I decided to write cgi in c instead of perl. It's not as easy because there is no nice library that I've found, but it should actually work.

t1mmy
08-11-2004, 09:33 AM
i've actually encountered a similar problem, where i want my cgi script to do some text processing in the background. in this case, i have my script call a shell script using wrap.sh.

it all works fine when i run it elsewhere, but it doesn't seem to work when in my cgi-bin directory. any ideas why?

H-street
08-26-2004, 08:47 PM
easiest way is probably to just do a system call..


#!/usr/bin/perl

(@data) = `helloWorld`;
$output = join("",@data);


you can also substitute `programName`; with system("programName");

i am pretty sure there is a way to do it via file handle but i find system calls just as effective.

i believe the file handle operation something like but i've never really used it so you may want to just look it up via the WWW..

open(EXEC," | helloWorld");
$output = (<EXEC>);
close EXEC;