Reputation: 314
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.
Upvotes: 3
Views: 1578
Reputation: 1942
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
Upvotes: 3