def spell(): form = SpellForm() #if login_user(user) == False: #flash('Please Log In', 'danger') #return redirect(url_for('login')) curr = current_user.username if form.validate_on_submit(): flash('Submitted Successfully', 'success') inputtext = form.inputtext.data with open('userinput.txt', 'w') as f: f.write(form.inputtext.data) f.close() #print(inputtext) spellout = subprocess.run(['./a.out', 'userinput.txt', 'wordlist.txt'], check=True, stdout=subprocess.PIPE, universal_newlines=True) #use if using python3.6 #spellout = subprocess.run(['./a.out', 'userinput.txt', 'wordlist.txt'], capture_output=True, text=True) # stderr=subprocess.DEVNULL with open('mispelled.txt', 'w') as g: g.write(spellout.stdout) g.close() with open('mispelled.txt', 'r') as g: mispelled = g.read().replace('\n', ', ').strip().strip(',') g.close() print(inputtext) print(mispelled) newlog = spellTable(username=curr, querytext=inputtext, queryresults=mispelled) db.session.add(newlog) db.session.commit() #spellout2 = spellout.stdout #print(spellout.stdout) return render_template('spell_check.html', title = 'Spell Checker', pagename = 'Spell Check Page', textout = inputtext, misspelled = mispelled, form = form) return render_template('spell_check.html', title = 'Spell Checker', pagename = 'Spell Check Page', form = form)
def spell_check(): textout = None misspelled = None form = SpellForm() if form.validate_on_submit(): textout = request.form['inputtext'] filename = urandom(32).hex() f = open(filename, 'w') f.write(textout) f.close() stdout, stderr = Popen(['./a.out', filename, 'wordlist.txt'], stdout=PIPE, stderr=STDOUT).communicate() misspelled = stdout.decode().replace('\n',',') p = Popen(['rm', filename], stdout=PIPE, stderr=STDOUT) return render_template('spell_check.html', \ form=form, textout=textout,misspelled=misspelled)