dso89762 2014-11-23 17:08
浏览 30
已采纳

带有/ arguments的PHP EXECUTE PERL

I have the following php script which needs to call a perl script along with the arguments. If I have the paths correct, is there anything wrong with the syntax? The php and the perl on server side. The php receives information (the $GET['zipc'] thru a url. The perl script will produce an xml file back on the server. I keep getting unexpected 'exec' (T_STRING) on line 8. Thanks for any advice.

<?php
$zipc="-Z";
$lineup="-Y USA";
$fformat="-U";
$duration="-d 2";
$outfile="-o";
$ofile="guide.xml"
exec("perl http://www.myserver.com/myperl.pl" $zipc $_GET['zipc'] $lineup $fformat $duration           $outfile "http://www.myserver.com/myfile.xml");
print"FINALLY GOT TO END";
?>

EDIT: Well I thought it was all worked out. Now I get the following error: Fatal error: Only variables can be passed

According to the tech support people where I have the scripted hosted, I have to rewrite the line of code that contains the exec so as not to open connections. Kinda at loss on this one. Any advice?

EDIT 2: The problem lies in the array. From what I understand an array can not be passed as shown in the answer without generating an error. To fix the problem I concatenate the variable and the $_GET into one variable. Seemed to fix the problem.

  • 写回答

1条回答 默认 最新

  • drbii0359 2014-11-23 17:51
    关注

    The second argument to the exec() function is an array. You have multiple syntax errors in your code because you have simply listed a bunch of variables without putting them inside of an array.

    Even if exec() did take a long list of parameters, which it doesn't, your code would still not work because you didn't separate them with commas.

    This should work (note the changes on lines 7 & 8):

    <?php
    $zipc="-Z";
    $lineup="-Y USA";
    $fformat="-U";
    $duration="-d 2";
    $outfile="-o";
    $ofile="guide.xml";
    exec("perl http://www.myserver.com/myperl.pl", array($zipc, $_GET['zipc'], $lineup, $fformat, $duration, $outfile, "http://www.myserver.com/myfile.xml"));
    print"FINALLY GOT TO END";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?