簡體   English   中英

使用PHP exec在bat文件中執行git命令

[英]Executing git commands in bat file with PHP exec

我正在嘗試使用PHP,exec和批處理文件執行多個git命令。 當我從cmd窗口執行bat文件時,它運行完美。 但是由於某種原因,當我使用exec(在PHP中)調用bat文件時,它僅執行直到call git add -A 提交突擊隊未執行。 當我手動執行它(commit命令),然后再次運行腳本時,文件被推送到存儲庫中。問題似乎是,如果腳本通過exec中的exec執行,則腳本不想提交文件。 PHP。

這是我的PHP:

exec('C:\wamp\www\git.bat "C:/wamp/www/project" "project"');

這是我的蝙蝠文件:

@echo off
set drupal_root=%1
set repo_name=%~2

pushd %drupal_root%
call git init
call git remote add origin https://repo-url/%repo_name%.git
call git add -A
call git commit -m "Initial commit"
call git push origin master

任何人都知道原因可能是什么?

按照“ 運行git bash腳本的Windows快捷方式 ”,嘗試執行bash腳本(使用Git for Windows bash shell)而不是bat腳本:

exec('C:\Git\bin\sh.exe" --login -i C:\wamp\www\myscript.sh "C:/wamp/www/project" "project"');

(將C:\\Git\\bin\\sh.exe替換為您在Windows上安裝Git的路徑。)

使用myscript.sh

#!/bin/bash

drupal_root=$1
repo_name=$2

cd $drupal_root
git init
git remote add origin https://repo-url/${repo_name}.git
git add -A
git commit -m "Initial commit"
git push -u origin master

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM