import flask
import subprocess
import time          #You don't need this. Just included it so you can see the output stream.
from flask import Flask, request, render_template

app = Flask(__name__)

@app.route('/')
def my_form():
    return render_template('my-form.html')

@app.route('/', methods=['POST'])
def my_form_post():
	text = request.form['text']
	file = r'./debug.txt'
	y = "file ret2win"
	with open (file,'w') as filex:
		filex.write('{}\n'.format(y))
		filex.write('{}\n'.format(text))

@app.route('/debug')
def index():
    def inner():
        proc = subprocess.Popen(
            ['gdb -x debug.txt'],             #call something with a lot of output so we can see it
            shell=True,
            stdout=subprocess.PIPE
        )

        for line in iter(proc.stdout.readline,''):
#            time.sleep(1)                           # Don't need this just shows the text streaming
            yield line.rstrip() + '<br/>\n'

    return flask.Response(inner(), mimetype='text/html')  # text/html is required for most browsers to show th$

app.run(debug=True, port=5000, host='0.0.0.0')

