我正在开发一个将github存储库拉到服务器上的php应用程序。Github webhooks调用php文件。
我想使用php执行一个cmd命令。我假设我需要apache权限,但我不知道如何授予它们。
下面的php代码创建并运行一个mkdir.bat和一个gitclone.bat。mkdir成功运行,它会创建一个空文件夹,但gitclone不会创建任何文件夹或文件。当我手动运行gitclone时,它确实会创建文件夹和文件。
file_put_contents("mkdir.bat", "mkdir test");
exec("mkdir.bat");
file_put_contents("gitclone.bat", "git clone https://github.com/gutyina700/WPTG.git");
exec("gitclone.bat");发布于 2019-04-14 20:58:31
我在我的电脑上执行你的代码
file_put_contents("gitclone.bat", "git clone https://github.com/gutyina700/WPTG.git");
exec("gitclone.bat 2>&1",$o);
print_r($o);额外的代码是检查cmd的输出,它返回"git command not exsists“,因此您只需添加一行如下所示
<?php
putenv("PATH=C:\Program Files\Git\cmd");
file_put_contents("gitclone.bat", "git clone https://github.com/gutyina700/WPTG.git");
exec("gitclone.bat 2>&1",$o);
print_r($o);
?>这是正常工作的。
https://stackoverflow.com/questions/55674873
复制相似问题