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";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址
  • ¥15 elmos524.33 eeprom的读写问题
  • ¥15 使用Java milo连接Kepserver服务端报错?
  • ¥15 用ADS设计一款的射频功率放大器
  • ¥15 怎么求交点连线的理论解?
  • ¥20 软件开发方法学习来了
  • ¥15 微信小程序商城如何实现多商户收款 平台分润抽成