PDA

View Full Version : System call using backticks


kevygee
08-02-2004, 06:22 PM
I'm writing a perl/cgi script where I need to run a different program (a compiled c program). I've tried using backticks in order to catch the output (for error handling purposes). Here are a couple lines of what I've tried:

my @programCall = `./programName args`;
print "@programCall";
OUTPUT:
(nothing, and the program doesn't run)

my @programCall = `exec $fullPath/programName args`;
print "@programCall";
OUTPUT:
sh: fullPath/programName: cannot execute

I'm not really sure how to get this program to run. I've changed permissions on all folders and files to 755, so if it's a permission problem, I don't know what else to change.

I hope someone can help!! Thanks.

dswimboy
08-02-2004, 10:09 PM
open(PROG, "program args |") or die "can't run: $!\n";
while (<PROG>) {
$output .=$_;
}
close PROG;

kevygee
08-02-2004, 10:56 PM
That worked better I think. At least now I get to see what the errors are. And the error I get is permission denied.

So, I have this executable, let's say, runMe, and it's in the same directory as my cgi script (cgi-bin). When I use file handles [open(PROG, "runMe |") or print "unable to run $!" ] in the cgi script run from the browser it says permission denied. But from the command line it runs fine. Obviously my cgi-bin directory is the correct permissions because the cgi script runs, and the program, runMe, is set as read and execute everyone.

I don't see where the permission error is coming from. Any ideas?