Reading git output with PHP exec () function

I am writing a deployment command for my framework command line tool. It uses git for deployment.

I have a line where I do this:

exec("git push {$remote} {$branch}:{$branch}", $shell_output, $status); 

I would like to get push output inside $shell_output , but it doesn't happen (the output just appears on the terminal). I think because git is an external program and therefore creates a new output stream?

I tried using the output buffer described here to no avail. I am sure there is something on SO that can answer this, but could not find it after a long dig.

So any help would be greatly appreciated :)

+4
source share
1 answer

git sends its output to STDERR and not to STDOUT, so you will need to redirect this using the following:

git push REPO --progress 2>&1

or to file:

git push REPO --progress > /path/to/file 2>&1

+9
source

Source: https://habr.com/ru/post/1446103/


All Articles