Skip to content
Advertisement

Multiple commands in Symfony Process Component

I’m trying to execute multiple commands using Symfony Process Component but second command is not being processed. What am I doing wrong?

        $process = new Process('sshpass -p password ssh user@host');
        $process->run();
        if (!$process->isSuccessful()) {
            throw new ProcessFailedException($process);
        }
        echo $process->getOutput();

        $process1 = new Process("sudo reboot -f");
        $process1->run();
        if (!$process1->isSuccessful()) {
            throw new ProcessFailedException($process1);
        }
        echo $process1->getOutput();

Advertisement

Answer

Process are isolated, the second will not be executed inside the ssh session you open at the top of your code.

You must use only one process todo that.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement