ssh2_exec:等待进程结束以运行下一个 [英] ssh2_exec: wait end of a process to run next

查看:40
本文介绍了ssh2_exec:等待进程结束以运行下一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ssh2_exec 运行命令,但看起来它在 $stream1 进程结束之前运行 $stream2.如何仅在 $stream1 结束后运行 $stream2?

I am running a command using ssh2_exec, but looks like it runs the $stream2 before the end of $stream1 process. How do I run $stream2 only after the end of $stream1?

<?php
$connection = ssh2_connect('shell.example.com', 22);
ssh2_auth_password($connection, 'username', 'password');

$stream1= ssh2_exec($connection, 'command to run');

$stream2 = ssh2_exec($connection, 'command to run 2');

?>

推荐答案

默认情况下不启用阻塞的事实是愚蠢的.这就是为什么我更喜欢 phpseclib 的 SSH.东西与 phpseclib 一起按预期工作.例如.

the fact that blocking isn't enabled by default is stupid. this is why i like SSH by phpseclib so much better. stuff just works as expected with phpseclib. eg.

<?php
include('Net/SSH2.php');

$ssh = new Net_SSH2('shell.example.com', 22);
$ssh->login('username', 'password');

$output = $ssh->exec('command to run');
$ssh->exec('command to run 2');
?>

这篇关于ssh2_exec:等待进程结束以运行下一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆