我正在使用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_command是我执行的两个命令。execute命令是执行命令并返回流的函数。Execute_command函数如下所示:-
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_command函数总是返回null。那么,我如何使用ssh2_exec执行两个命令呢?
感谢你的帮助
发布于 2015-07-16 02:22:53
拼写错误:
$dur_command = 'ffmpeg -i '.$status. '2>&1 | grep "Duration"';
^^---no space你在制作
ffmpeg -i foo2>&1 | grep "Duration",它被执行为
ffmpeg -i foo2 >&1 | grep "Duration"https://stackoverflow.com/questions/31438008
复制相似问题