Python Forum
Show powershell errors in flask-wtf web form
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Show powershell errors in flask-wtf web form
#6
ok im doing this

@app.route('/password', methods=['GET', 'POST'])
def password():
    form = PasswordForm()
    if request.method == 'POST' and form.validate():
        try:
            result = subprocess.run(f'powershell.exe $cred = Import-CliXml -Path C:\\python\\cred.xml; Set-ADAccountPassword -Credential $cred -Identity {form.un.data} -OldPassword (ConvertTo-SecureString -AsPlainText {form.op.data} -Force) -NewPassword (ConvertTo-SecureString -AsPlainText {form.cnp.data} -Force) -Server {form.dom.data}', capture_output=True, text=True, shell=False)
            print("STDOUT:", result.stdout)
            print("STDERR:", result.stderr)
        except:
            print("something went wrong")
        return '<h1>The username is {}. The old password is {}. the new password is {}. changing for domain {}'.format(form.un.data, form.op.data, form.cnp.data, form.dom.data)
    return render_template('password.html', form=form)

if __name__ == '__main__':
    app.run(debug=True)
but when the subprocess command fails its not showing the print message in except

also if the sub process command fails i dont want it to display that return line ie to show what you typed in username old password, new password, domain
Reply


Messages In This Thread
RE: Show powershell errors in flask-wtf web form - by robertkwild - Jun-28-2024, 03:00 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Errors and warning in Flask yogeshhooda 1 791 Aug-04-2024, 12:42 PM
Last Post: snippsat
  Beta6 of my password flask-wtf web form robertkwild 3 1,369 Jul-02-2024, 10:30 AM
Last Post: robertkwild
  Cant get powershell script to run with subprocess robertkwild 2 1,699 Jun-27-2024, 01:23 PM
Last Post: robertkwild
  Running powershell command in flask wtf form robertkwild 10 2,782 Jun-27-2024, 09:49 AM
Last Post: robertkwild
  Passing web form to powershell robertkwild 1 1,114 Jun-14-2024, 10:16 AM
Last Post: Akshiya
  using split in my flask wtf form robertkwild 1 897 Jun-11-2024, 05:19 PM
Last Post: deanhystad
  making a form purely with flask-wtf robertkwild 15 3,782 Jun-01-2024, 11:53 AM
Last Post: robertkwild
  using PowerShell from Python script for mounting shares tester_V 8 2,777 Mar-12-2024, 06:26 PM
Last Post: tester_V
  PowerShell & Python deep_logic 2 1,939 Jun-06-2023, 06:34 AM
Last Post: buran
  PIL Image im.show() no show! Pedroski55 2 4,990 Sep-12-2022, 10:19 PM
Last Post: Pedroski55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020