3

i have one problem with php and perl, i need execute perl script, from my website php with codeigniter, but the execution of the script is not evident. I explain better.

The perl Script generate one csv file, when i execute in console, it works perfectly, but when I run it from PHP, it does not generate the file, and it does not give any errors during the execution, so I think, it's just not running.

the script needs 3 input parameters, which are previously concatenated in the execution of the same. But even when I try to force the execution of the script, placing the values inside the execution command, nothing happens.

I have tried to execute it in the following ways:

$perl_script = './zc_csv_dist_crd_3.pl' . ' ' . $ctac_corre . ' ' . $codigo. ' ' . $num_dist;
exec($perl_script);

or

system($perl_script);

or directly

shell_exec("./zc_csv_dist_crd_3.pl 7736 311745421 42906");
#or
exec("./zc_csv_dist_crd_3.pl 7736 311745421 42906");
#or
system("./zc_csv_dist_crd_3.pl 7736 311745421 42906");

I want to clarify that I do not need a return value, even the perl script, has no return value, since the file is generated empty or with data, and both cases are valid. I've read that it can be a problem of permission, but I'm new to perl, php and linux. I leave the linux server features, with the hope that someone can guide me.

Very grateful with your help in advance.

PD: I have read patiently, the forums in stackoverflow, the PHP manuals and even then I can not make it work, I know I'm jumping something, but I can not see it by now.

  • CentOS Linux release 7.3.1611 (Core) NAME="CentOS Linux" VERSION="7 (Core)" ID="centos" ID_LIKE="rhel fedora" VERSION_ID="7" PRETTY_NAME="CentOS Linux 7 (Core)" ANSI_COLOR="0;31" CPE_NAME="cpe:/o:centos:centos:7" HOME_URL="https://www.centos.org/" BUG_REPORT_URL="https://bugs.centos.org/" CENTOS_MANTISBT_PROJECT="CentOS-7" CENTOS_MANTISBT_PROJECT_VERSION="7" REDHAT_SUPPORT_PRODUCT="centos" REDHAT_SUPPORT_PRODUCT_VERSION="7" CentOS Linux release 7.3.1611 (Core) CentOS Linux release 7.3.1611 (Core) – Darwin Delgado Sep 27 '18 at 21:18
  • thar is the linux server – Darwin Delgado Sep 27 '18 at 21:18
  • 1
    Have you checked the return value? If not, you should so that you can narrow down the problem. The perl script could be failing to execute or it does execute but throws a fatal error. – Ron Bergin Sep 27 '18 at 21:29
  • 1
    Have you tried using the full path instead of the relative path? – Ron Bergin Sep 27 '18 at 21:31
  • Ron, i Use the full path, and the perl script, it works well, I even show on the screen, the command to execute it, I copy it and execute it on the server console, and it runs without problems, or errors – Darwin Delgado Sep 28 '18 at 11:25
  • If it runs in the console but not in the web app, then it's almost always due to a difference in environment. Based on your comments so far, it's unclear if the script is failing to be executed or if it's executing but failing in some way. Checking the return code of the various methods of execution could answer that question. What are the permission settings for the script? Does the web server user have rights to run it? Is php's safe mode enabled? – Ron Bergin Sep 28 '18 at 15:39
  • I'm not sure if you're aware of this but a return value is not the same as a return code. What kind of error checking/handling are you doing in the script? – Ron Bergin Sep 28 '18 at 15:45
  • Where does the script create the csv file? Does the web server account have rights to write to that location? Have you tried to su to the web server account then run the script? – Ron Bergin Sep 28 '18 at 15:51
  • Did you assure the directory where the csv is written is writable for the web server user? Many times /tmp is used to ensure that, but local directories are better controllable. -- Maybe [popen()](http://php.net/manual/en/function.popen.php) is a friend. Instead of waiting for Perl script termination and then reading your file, you can pipe your data directly to the PHP script without creation of an intermediate file. Any output can also be written by the PHP script then. – syck Oct 11 '18 at 12:55

1 Answers1

0

You probably have your PHP code running in Safe Mode, which in your case will not allow you to use the functions you mentioned, check this out Safe Mode Functions

I found out that there are some similar questions to yours in these links: Question 1 Question 2

I hope it helps.

Bruno
  • 924
  • 9
  • 20