0
   import subprocess
   subprocess.call('gcc a.c', shell=True)
   subprocess.call('./a.out', shell=True)

I am executing this statement to compile a ".c" file. I got the output in the backend.

But how can I get the output of that C program in a python text area (I'm using tkinter, python 2.7 )?

Another problem is, I'm not able to scan input data but only able to compile programs which will not take input data.

1 Answer 1

1

you can use subprocess.Popen and redirect stdout to PIPE and test simply read stdout e.g complie.stdout.readlines() in you set text area calls

import subprocess

complie = subprocess.Popen('gcc a.c', stdout=subprocess.PIPE,shell=True)
runprog  = subprocess.Popen('./a.out', stdout=subprocess.PIPE,shell=True)

print (complie.stdout.readlines())
print (runprog.stdout.readlines())

instead of prints you can put complie.stdout.readlines() in your text area set calls

Example Code :

import subprocess
from tkinter import *

#Example on Windows

root = Tk()
T = Text(root, height=2, width=200)
T.pack()

complie = subprocess.Popen('ping google.com', stdout=subprocess.PIPE,stdin=subprocess.PIPE ,shell=True)
complie.wait()
outcome = complie.stdout.readlines()
print(outcome)
T.insert(END, outcome)
mainloop()

Hope this helps

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.