我尝试使用Symfony Process Component执行多个命令,但第二个命令未被处理。我做错了什么?
$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();
答案 0 :(得分:0)
这是使用symfony process
运行多个命令的方法$process = new Process('sshpass -p password ssh user@host');
$process->run(); //Run the command (whole process)
if (!$process->isSuccessful()) { //Executes after the command finishes
throw new ProcessFailedException($process);
}
echo $process->getOutput(); //Output the result (optional)
$process->setCommandLine('sudo reboot -f'); //Set a new Command to the current process
$process->run(); //Run this process again
if (!$process->isSuccessful()) { //Executes after the command finishes
throw new ProcessFailedException($process);
}
echo $process->getOutput(); //Next output (also optional)
答案 1 :(得分:-1)
进程被隔离,第二个进程不会在您在代码顶部打开的ssh会话中执行。
您必须只使用一个进程。