3

Here is my push.bat file

echo "Hello world!"
cd abhishek3/
call git add .
call git commit -m "sadf"
call heroku accounts:set abhishek84 
call git push heroku master

I am able to push to my repository by running push.bat file in cmd

I want to push to my repo from php, tried following snippets but none of them worked for me.

exec("psexec -d push.bat");

Result: PHP page loads indefinitely

$WshShell = new COM("WScript.Shell");
$oExec = $WshShell->Run("cmd /C abhishek3.bat, 0, false);

Result: Page stops loading after a while and nothing works

exec("cmd.exe /c abhishek3.bat")

Result: Page stops loading after a while and nothing works

EDIT: Tried the following snippet but nothing worked.

exec("hstart.exe /NOCONSOLE \"cmd.exe /c \"abhishek3.bat\"\"");

The above snippet runs successfully when run from cmd but when run from php through exec() didn't worked. Download hstart (Hidden Start Binary)

2
  • As you're saying "page loads" I assume you are testing via web server? did you try from php cli? Probably the webserver is running with other privilies tha your user and that stops it? Commented Oct 5, 2014 at 12:33
  • I am running the webserver from localhost. When I run php -r "$ret = exec('abhishek3.bat'); echo $ret;" from cmd it executes the batch file successfully. If I run it from webpage it doesn't performs the push.. Commented Oct 5, 2014 at 12:48

1 Answer 1

1
  1. check the permissions for the web users are correct (It can access the files and execute git)
  2. check the path for git and any environment variables it may need. You may have to set those environment variables in your script and use absolute paths)
  3. check IIS or apache (whichever you are using) is allowed to execute programs in general and bat files (for example if it is apache, you may have to configure httpd.conf or htaccess depending on your configuration)
Sign up to request clarification or add additional context in comments.

7 Comments

git init runs successfully.. git commit runs successfully... git push doesn't runs when run through php web page (It runs when executed from PHP CLI..) What can be the cause of it ?
it looks like a firewall restriction. try (1) turning off iptables temporarily (2) turning off selinux temporarily.
I just remembered this is windows. Try turning off the firewall. This is also powershell, check executionpolicy and set it to unrestricted
Firewall was already disabled. Also I set the execution policy to unrestricted but git push heroku master didn't worked.
probably missing the SSH key / credentials/ known_hosts as a web user
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.