Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php ssh2_exec命令不工作的情况下运行2个命令_Php - Fatal编程技术网

在php ssh2_exec命令不工作的情况下运行2个命令

在php ssh2_exec命令不工作的情况下运行2个命令,php,Php,我正在使用php执行linux命令。但当我尝试一个接一个地执行两个命令时,第二个命令总是返回空流。我的php函数或执行命令是: $file_name = $_GET['name']; $fielss = explode(".", $file_name); $year = substr($file_name, 0, 4); if(sizeof($fielss) == 1) {

我正在使用php执行linux命令。但当我尝试一个接一个地执行两个命令时,第二个命令总是返回空流。我的php函数或执行命令是:

    $file_name = $_GET['name'];
            $fielss = explode(".", $file_name);
            $year = substr($file_name, 0, 4);

            if(sizeof($fielss) == 1)
            {
                $command ='find /mnt/mediamanager/'.$year.' -name '.$file_name.'.'.'mxf';
            }
            else if(sizeof($fielss) == 2)
            {
                $ext = end(explode(".", $file_name));
                $command ='find /mnt/mediamanager/'.$year.' -name '.$fielss[0].'.'.$ext;
            }

// Command first
            $connection1 = $this->ssh->Create_connection('192.168.1.102', 'root', 'admin123');
            $status = $this->ssh->execute_command($connection1, $command);
            ssh2_exec($connection1, 'logout');
            ssh2_exec($connection1, 'exit');
            unset($connection1);

// Command second       
            $connection = $this->ssh->Create_connection('192.168.1.102', 'root', 'admin123');
            $dur_command = 'ffmpeg -i '.$status. '2>&1 | grep "Duration"';
            $duration = $this->ssh->execute_command($connection, $dur_command);
在这段代码中,$command和$dur_命令是我执行的两个命令。执行命令是执行命令并返回流的函数。Execute_命令函数如下所示:-

function execute_command($connection, $command)
    {
        if (!($stream = ssh2_exec($connection, $command))) 
        {
            return FALSE;
        } 
        else 
        {
            $errorStream = ssh2_fetch_stream($stream, SSH2_STREAM_STDERR);
            stream_set_blocking($errorStream, true);
            stream_set_blocking($stream, true);
            // search file into the varibales.
            $file = stream_get_contents($stream);
            return $file;
        }
    }
第一个命令工作正常,但在第二个命令中,execute_命令函数始终返回null。那么如何使用ssh2_exec执行2个命令呢

感谢您的帮助

打字错误:

        $dur_command = 'ffmpeg -i '.$status. '2>&1 | grep "Duration"';
                                              ^^---no space
你在制作

 ffmpeg -i foo2>&1 | grep "Duration"
它被执行为

 ffmpeg -i foo2 >&1 | grep "Duration"
打字错误:

你在制作

 ffmpeg -i foo2>&1 | grep "Duration"
它被执行为

 ffmpeg -i foo2 >&1 | grep "Duration"

我们可以执行这样的两个命令吗。我读到很多线程最大的调用是我们不能执行两个命令。但当我手动或硬编码放置$dur_命令时,它正在运行。但当我使用$status时,它不运行。我也检查错误,你给,但它仍然不工作@我们可以执行这样的两个命令。我读到很多线程最大的调用是我们不能执行两个命令。但当我手动或硬编码放置$dur_命令时,它正在运行。但当我使用$status时,它不运行。我也检查错误,你给,但它仍然不工作@马克B