Home > Back-end >  catch git output from flask
catch git output from flask

Time:05-16

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

CodePudding user response:

it's working with subprocess.check_output:

m = subprocess.check_output('git status', shell=False)

note that shell must be set to False

  • Related