0

I need to execute many commands with Process Component.

$commands = [
                ["mkdir", "-p", path)],
                ["cd", path],
                ["rm", "-f", $archiveName, $sqlDbName . '.sql'],
                [$this->dumpCommand($sqlDbName)],
                ["tar", "zcfP", $archiveName, $sqlDbName . '.sql'],
                ["rm", "-f", $sqlDbName . ".sql"],
           ];

foreach ($commands as $command) {
    $process = new Process($command);
    $process->run();
    return $process->getOutput();
}

I think only the first command works. I have no errors. Someone knows why?

rcn
  • 53
  • 3

1 Answers1

0

When you use the return in the loop which is used in the function the loop is broken. in your code, the code is running until the return (one time) then returns the output and stops to iterate.

you should remove the return $process->getOutput(); to process all commands.

A.Seddighi
  • 1,695
  • 1
  • 20
  • 43