简体   繁体   English

用于执行exec的PHP脚本

[英]PHP script to execute exec

I am writing a PHP script to upload a file that execute other c files by using system calls fork() , and exec() , and execl() . 我正在编写一个PHP脚本来上传一个文件,该文件使用系统调用fork()exec()execl()来执行其他c文件。 Unfortunately execl() function did not work. 不幸的是execl()函数不起作用。
In more details, the PHP script , execute exec() function as: 更详细的PHP脚本,执行exec()函数:

$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: 执行p1,这是p1.c的可执行文件,p1.c程序调用execl()为:

execl("./p2", "./p2", "a.param","test.txt", NULL); 

to execute p2 which is the executable file of p2.c. 执行p2,它是p2.c的可执行文件。 As the result execl() in p1.c is not executed, and p2.c is not executed. 结果是p1.c中的execl()没有执行,并且没有执行p2.c. Any suggestions. 有什么建议么。

As stated in shell_exec documentation , this function is only enabled if safe_mode is disabled in PHP configuration. shell_exec文档中所述 ,只有在PHP配置中禁用safe_mode才会启用此功能。

To disable it, (only for PHP prior to 5.4 ), you must include the following line in php.ini : 要禁用它(仅适用于5.4之前PHP ),必须在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 ). 您使用相对路径( ./app/p1./p2 )调用./app/p1 ./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. 要解决此问题,只需在两种情况下使用文件的完整路径即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM