I am writing a PHP script to upload a file that execute other c files by using system calls fork()
, and exec()
, and execl()
. Unfortunately execl() function did not work.
In more details, the PHP script , execute exec()
function as:
$output =shell_exec('./app/p1';
echo "<pre>$output</pre>"; )
to execute p1 which is the executable file of p1.c, and the p1.c program calls execl() as:
execl("./p2", "./p2", "a.param","test.txt", NULL);
to execute p2 which is the executable file of p2.c. As the result execl() in p1.c is not executed, and p2.c is not executed. Any suggestions.
As stated in shell_exec
documentation, this function is only enabled if safe_mode
is disabled in PHP configuration.
To disable it, (only for PHP prior to 5.4), you must include the following line in php.ini
:
safe_mode = Off
Another possible problem could come from current path. You're calling the binnaries using relative paths (./app/p1
and ./p2
). Are you sure that these binnaries are in the current working directory?
To get rid of this problem, simply use the file's full path in both cases.