douna3367 2014-08-28 11:23
浏览 402

Exec返回空白数组

I've seen more than a few questions on this whilst searching, but none with a working answer, just recommendations of other things to try

$server = "IPADDRESS";
$username = "USER";
$port = "22";
$ftpuser = "FTPUSER"
$ftppass = "FTPPASS"

$command = "/usr/local/psa/bin/subscription --create " . $domain . " -owner admin -service-plan 'Default Domain' -ip " . $server . " -login " . $ftpuser . " -passwd '" . $ftppass . "'";
$cmd_string = "ssh -p ".$port." ".$username."@".$server." ".$command;
exec($cmd_string, $output);
echo $command;
echo $output;

Using uptime as a command works fine, and taking the exact output of the $command and manually pasting it also works fine with a usual output of SUCCESS: Creation of domain DOMAIN completed - However when running this, it simply outputs 'Array', with no contents. Am I missing something?

  • 写回答

1条回答 默认 最新

  • dongwen3437 2014-08-28 11:27
    关注

    PHP manual' page about exec is clear about it :

    If the output argument is present, then the specified array will be filled with every line of output from the command. Trailing whitespace, such as , is not included in this array. Note that if the array already contains some elements, exec() will append to the end of the array. If you do not want the function to append elements, call unset() on the array before passing it to exec().

    It returns an array filled with each lines of the exec call.

    So in your case, you should use :

    echo $output[0]; // The first and only line
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于大棚监测的pcb板设计
  • ¥20 sim800c模块 at指令及平台
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计