'catch git output from flask
I'm trying to roll out a quickie flask app to get git statistics from a certain repo for coworkers to see.
import os, sys
from flask import Flask, Response
app = Flask(__name__)
@app.route('/git')
def zooi():
out = os.popen('git -C /mygitrepo status').read()
return Response(out, mimetype='text/html')
But going to http://127.0.0.1:5000/git does not give any output, and also no error so git is found and started. This does show output:
out = os.popen('echo test').read()
and this:
out = os.popen('gitxxx status').read()
emits:
'gitxxx' is not recognized as an internal or external command
how do I catch output from git from python / flask?
This on windows BTW
Solution 1:[1]
it's working with subprocess.check_output:
m = subprocess.check_output('git status', shell=False)
note that shell must be set to False
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Serve Laurijssen |