我打电话给一条特别的路线,试图git pull。我在控制器内使用symfony/process,如下所示:
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;
}
});
}当我到达路线时,它会返回:
ERR > 'git' is not recognized as an internal or external command, operable program or batch file.然后我尝试将命令更改为任何其他命令,如ls、npm install、rm等。它仍然返回相同的错误。
发布于 2021-02-01 01:39:26
为了运行系统命令,例如从shell或cmd(无论是在windows、linux或mac上):
$process = Process::fromShellCommandline('inkscape --version');
$process->run(function ($type, $buffer) {
if (Process::ERR === $type) {
echo 'ERR > ' . $buffer;
} else {
echo 'OUT > ' . $buffer;
}
});产出如下:
OUT > Inkscape 1.0.2 (e86c870879,2021-01-15) ERR > Pango版本: 1.48.0
不要忘记阅读文档:
https://symfony.com/doc/current/components/process.html#installation
https://stackoverflow.com/questions/64810453
复制相似问题