Show powershell errors in flask-wtf web form

hi all,

so im really getting along with my flask-wtf form and im nearing its completion

now i want to show if powershell errors, i want it to show on the web form

this is my py script

from flask import Flask, render_template, request
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, BooleanField, DecimalField, RadioField, SelectField, TextAreaField, FileField, SubmitField
from wtforms.validators import InputRequired, Length, DataRequired, EqualTo, Regexp, ValidationError
import re
import subprocess

app = Flask(__name__)
app.config['SECRET_KEY'] = 'secretkey'

class PasswordForm(FlaskForm):
    un = StringField('Username', [InputRequired(message='please enter your Username')])
    op = PasswordField('Current Password', [InputRequired(message='please enter your current password')])
    np = PasswordField('New Password', [InputRequired(message='please enter your new password')])
    cnp = PasswordField('Confirm New Password')
    dom = SelectField('Domain', choices=[('', 'prod'), ('', 'corp'), ('', 'robo84')])
    def validate_un(form, field):
        if not ==
            raise ValidationError('Username needs to be Lowercase')
    def validate_np(form, field):
            if any (name in for name in".")):
                raise ValidationError('New password cant contain firstname or lastname')
        if ==
            raise ValidationError('New password cant match Current password')
        if len( < 12:
            raise ValidationError('New password must be at least 12 characters')
        if not"[0-9]",
            raise ValidationError('New password has to contain one number')
        if not"[a-z]",
            raise ValidationError('New password has to contain one lower case character')
        if not"[A-Z]",
            raise ValidationError('New password has to contain one upper case character')
        if not"[\`\¬\!\"\£\$\%\^\&\*\(\)\-\_\=\+\\\|\[\]\;\'\#\,\.\/\{\}\:\@\~\<\>\?]",
            raise ValidationError('New password has to contain one special character')
        if not ==
            raise ValidationError('New password has to match Confirm new password')
@app.route('/password', methods=['GET', 'POST'])
def password():
    form = PasswordForm()
    if request.method == 'POST' and form.validate():'powershell.exe $cred = Import-CliXml -Path C:\\python\\cred.xml; Set-ADAccountPassword -Credential $cred -Identity {} -OldPassword (ConvertTo-SecureString -AsPlainText {} -Force) -NewPassword (ConvertTo-SecureString -AsPlainText {} -Force) -Server {}', shell=True)
        return '<h1>The username is {}. The old password is {}. the new password is {}. changing for domain {}'.format(,,,
    return render_template('password.html', form=form)

if __name__ == '__main__':

my html script

{% block content %}
    <h1>Change Password</h1>
    <form method="post" novalidate>
		<p>{{ form.un.label }}</p>
		<p>{{ form.un}}</p>
		{% if form.un.errors %}
			{% for error in form.un.errors %}
			{% endfor %}
		{% endif %}
		<p>{{ form.op.label }}</p>
		<p>{{ form.op}}</p>
		{% if form.op.errors %}
			{% for error in form.op.errors %}
			{% endfor %}
		{% endif %}
		<p>{{ }}</p>
		{% if %}
			{% for error in %}
			{% endfor %}
		{% endif %}
		<p>{{ form.cnp.label }}</p>
		<p>{{ form.cnp}}</p>
		{% if form.cnp.errors %}
			{% for error in form.cnp.errors %}
			{% endfor %}
		{% endif %}
		<p>{{ form.dom.label }}</p>
		<p>{{ form.dom}}</p>
		<input type="submit" value="Submit">

it works well but only problem is if they enter in there old password wrong ie op there not warned about it, it only shows in the cmd part but obviously the end user cant see this and can just see the html form

can i output the error in the same html script?

i want it not to run the command if it errors