gpt4 book ai didi

php - ssh2_exec : wait end of a process to run next

转载 作者:行者123 更新时间:2023-12-01 19:25:52 26 4
gpt4 key购买 nike

我正在使用 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');

?>

关于php - ssh2_exec : wait end of a process to run next,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24500704/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com