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');
?>