如何使用 Symfony\Component\Process\Process 运行 多个命令

How to run multiple commands with Symfony\Component\Process\Process

我们使用 https://www.cloudfoundry.org/ 托管我们的应用程序。 要连接到服务器,我们必须使用 cf ssh APP-NAME 而不是正常的 ssh 命令。

现在我想在服务器上编写一个简单的任务 运行ner,例如 https://deployer.org/ 到 运行 一些 artisan 命令。 为此,我厌倦了 Symfony\Component\Process\Process,它可以连接到服务器,但我无法保持对 运行 其他一些命令的连接。

有谁知道如何保持连接打开和运行一些命令?

这是我当前的代码:

use Symfony\Component\Process\Process;

$process = new Process("cf ssh APP-NAME");
$process->setPTY(true);

// Add some other commands like "php artisan migrate" 

$process->run();

echo $process->getOutput();

在远程服务器上执行命令与启动子进程完全不同。所以它不属于 Process 组件,而是属于另一个库。 尝试使用这个 phpseclib/phpseclib here you can find nice manual phpseclib/phpseclib manual.

或者这个ssh-client/ssh-client.

另外,看看这个 laravel 包 laravelcollective/remote