Show subprocess command output in text box of tkinter in Python

Example of subprocess output shown in text box of tkinter GUI in python language

from tkinter import *
import subprocess
import os
from tkinter import *
from subprocess import Popen, PIPE

root = Tk()
text = Text(root)

v_complete="EXPDP hjr/hr@pdb1 Directory=dbbackup REUSE_DUMPFILES=Y schemas=hr dumpfile=dbbackuphr.dmp logfile=hr.log"
#p1 = ,stdout=subprocess.PIPE, text = True)

def ls_proc():
    return Popen(v_complete,shell=True, stdout=subprocess.PIPE,stderr=subprocess.PIPE,universal_newlines=True)

with ls_proc() as p:
    if p.stdout:
        for line in p.stdout:
            text.insert(END, line)
    if p.stderr:
        for line in p.stderr:
            text.insert(END, line)

#text.insert(INSERT, p1.stdout)
#text.insert(END, "hello")


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.