简体   繁体   English

用PHP调用Perl脚本,传递变量并将结果放入文件中

[英]Calling Perl script with PHP, passing variables and put result into a file

I am near losing my mind cause of a perl script I want to call via PHP. 我几乎不介意要通过PHP调用的Perl脚本。

I have a PHP Form where I put in a MySQL Query which gets stored in a file and choosing some variables. 我有一个PHP表单,在其中放入了存储在文件中并选择一些变量的MySQL查询。

If I call any SHELL command like "top" ... everything works fine, but as soon as I try to call my perl script with variables, there are no results at all. 如果我调用任何诸如“ top”之类的SHELL命令……一切正常,但是一旦我尝试用变量调用我的perl脚本,就根本没有结果。

The file where the results should get stored stays empty. 结果应存储在其中的文件保持为空。

That's the calling part from the PHP File: 那是PHP文件的调用部分:

if (isset($_POST['submit'])) {
$file = 'query.sql';
$query = $_POST['query'];
file_put_contents($file, $query);
$command = "perl /home/www/host/html/cgi/remote-board-exec.pl -sqlfileexec query.sql > /home/www/host/html/cgi/passthrutest.txt";
exec($command, &$ausgabe, $return_var);

There is no error message and i already tried debug things, but nothing helped :( 没有错误信息,我已经尝试调试了,但是没有帮助:(

Are you sure that perl is being executed? 您确定正在执行perl吗? Perhaps you ought to replace the command with 'which perl' just to make sure, and to use the full path to Perl. 也许您应该将命令替换为“ which perl”以确保并使用指向Perl的完整路径。 Another idea is to make sure your: 另一个想法是确保您:

  • perl script is executable (use chmod) perl脚本是可执行的(使用chmod)
  • ensure it has '#!/usr/bin/perl' (or wherever your path to perl is) 确保它具有“#!/ usr / bin / perl”(或您的perl路径在哪里)
  • change the command to "/home/www/host/cgi/remote-board-exec.pl..." without the perl command 将命令更改为“ /home/www/host/cgi/remote-board-exec.pl ...”,而不使用perl命令
  • dump the contents of your output array ($ausgabe) as if the command fails to execute you may find out what is happening. 转储输出数组($ ausgabe)的内容,就好像命令无法执行一样,您可能会发现正在发生的情况。

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

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