1

I am trying to Make A U.I that takes the c++ code in the text box and displays the output or the errors. I am unable to Copy the result of the console that arises after compiling the code and running the Code. Also, I want to save the output or the errors in a file.

CODE:

from tkinter import *

import subprocess

root=Tk()

def exect():

    global e

    entry=e.get("1.0","end-1c")

    f=open('sample3.cpp','w')

    f.write(entry)

    f.close()



    #this is where problem is because it does not save the output

    subprocess.call(["g++","sample3.cpp"])

    subprocess.call("./a.out")

    #how do i run this code for sample inputs and then store its output



    root.destroy()

root.geometry("600x700")

x=Frame(root)

x.grid()

label=Label(root,text="write code for displaying hello world")

label.grid()

e=Text(root)

button=Button(root,text="submit",command=exect)

button.grid()

e.grid()

root.mainloop()

Also, How do I compile and save a program that takes Inputs?

EDIT: This question also seeks running the program for sample inputs which I did not find in the answer which this question was marked as duplicate to?

  • Duplicate of https://stackoverflow.com/questions/4965159/python-how-to-redirect-output-with-subprocess – Artemy Vysotsky Aug 26 '17 at 06:34
  • Possible duplicate of [Python: How to Redirect Output with Subprocess?](https://stackoverflow.com/questions/4965159/python-how-to-redirect-output-with-subprocess) – Artemy Vysotsky Aug 26 '17 at 06:35

0 Answers0