我正在使用 ssh2_exec 运行命令,但看起来它在 $stream1 进程结束之前运行 $stream2。如何仅在 $stream1 结束后运行 $stream2?
<?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');
?>
问题解决了:
@Barmar 建议我看看 php.net/manual/en/function.ssh2-exec.php#59324
我通过以下方式解决了这个问题:
<?php
$connection = ssh2_connect('shell.example.com', 22);
ssh2_auth_password($connection, 'username', 'password');
$stream1= ssh2_exec($connection, 'command to run');
stream_set_blocking($stream1, true);
// The command may not finish properly if the stream is not read to end
$output = stream_get_contents($stream1);
$stream2 = ssh2_exec($connection, 'command to run 2');
?>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)