Hello monks,

I need some advice with system calls. I have been researching for the past few days and have not been able to find what I'm looking for. I'm running a Perl CGI script from a webpage that needs to make some system calls. I'm running into a problem where no system calls will work at all. Not even a simple one such as "ls". Here's the important part of the code:

#! /usr/bin/perl -T use strict; use warnings; $ENV{"PATH"} = ""; chdir "/home/user/"; chomp($update_location); # $update_location is: # /home/user/test/update_test.pl # it's retrieved from the database my $cmd = sprintf("perl %s", $update_location); system($cmd); if ($? == -1) { logger("failed to execute: $!\n"); # logger is a simple sub that appends whatever is passed # to an error.txt file } elsif ($? & 127) { logger("child died with signal coredump\n"); } else { my $sys_code = $? >> 8; logger("child exited with value $sys_code\n"); }

When I run the code above, my error.txt file says "failed to execute: Permission denied". When I comment out the chdir line, error.txt says "failed to execute: No such file or directory".
Whether or not I comment out the chdir line, if I try a simple system call such as:

system("ls");

it responds with "failed to execute: No such file or directory".
Permissions are
/home/ drwxr-xr-x
/home/user/ drwxr-xr-x
/home/user/test/ drwxr-xr-x
/home/user/test/update_test.pl -rwxr-xr-x
I already ran chmod +x on update_test.pl and am able to run it from a terminal.

Any ideas as to why the system calls won't work? Thank you for any advice you can give me!


In reply to System calls from CGI script by whitdan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.