weixin_33722405 2014-07-25 16:49 采纳率: 0%
浏览 20

Laravel-返回SSH输出

Thanks for interest to this topic. I'm pretty new in Laravel and i have a little question. Maybe it's easy! I have an SSH module in my Laravel that works this way: The user fills the textarea element with Linux commands. The command is passed with Ajax to a method called getExecute() located in the 'controllers' folder I would like that this method returns me the full response of my SSH server, but this isn't happening. The only thing that the method returns is a blank space.

For example: I pass the command 'ls -la', and my response is all folders that the Linux find, like on terminal. Can someone help me please? Here is my code:

public function getExecute()
{
    if(\Request::ajax()):

        $ssh_command = \Input::get('ssh_command');
        $ssh_response = null;

        \SSH::run($ssh_command, function($line)
        {
            return $line.PHP_EOL;
        });

    endif;
}

OBS: The Ajax connection was tested and it's ok! Thank you!

  • 写回答

1条回答 默认 最新

  • weixin_33712881 2014-07-30 15:27
    关注

    Finally solved! Solution below:

    First i've created a variable called $output in my class.

    private $output;
    

    Then i modified my method to this:

    public function postExecute()
    {
        $ssh_command = \Input::get('ssh_command');
        $ssh_response = \SSH::run($ssh_command, function($line)
        {
            $this->output = $line.PHP_EOL;
        });
    
        return $this->output;
    }
    

    My method is not more Ajax, but i hope that all that i have to do is rollback to my ajax method like before.Thanks for all!

    评论

报告相同问题?

悬赏问题

  • ¥50 comsol稳态求解器 找不到解,奇异矩阵有1个空方程返回的解不收敛。没有返回所有参数步长;pid控制
  • ¥15 怎么让wx群机器人发送音乐
  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功