3

I was trying to git pull by calling a spesific route. I'm using symfony/process inside my controller like so:

public function pull()
{
    $process = new Process(["git","pull"]);
    $process->setWorkingDirectory(base_path());
    $process->run(function ($type, $buffer) {
        if (Process::ERR === $type) {
            echo 'ERR > '.$buffer;
        } else {
            echo 'OUT > '.$buffer;
        }
    });
}

when I hit the route it returns:

ERR > 'git' is not recognized as an internal or external command, operable program or batch file.

then I tried to change the command to any other command like ls, npm install, rm, etc... and it is still returning the same error.

2
  • What is the underlaying OS your app is running on? Commented Nov 12, 2020 at 20:39
  • @β.εηοιτ.βε my local dev runs on windows, but Im actually going to deploy it on linux Commented Nov 12, 2020 at 20:43

1 Answer 1

3

To everyone who comes here; In order to run the system commands such as from shell or cmd(either on windows or linux or mac):

$process = Process::fromShellCommandline('inkscape --version');

$process->run(function ($type, $buffer) {
    if (Process::ERR === $type) {
        echo 'ERR > ' . $buffer;
    } else {
        echo 'OUT > ' . $buffer;
    }
});

The output is:

OUT > Inkscape 1.0.2 (e86c870879, 2021-01-15) ERR > Pango version: 1.48.0

Don't forget to read the documentation:

https://symfony.com/doc/current/components/process.html#installation

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.