Have a working script that lets me select a PS script and pipes the output to a file. I'm trying to use the stdout=PIPE and instead output it to the blank tkinter text box. I'm about as green as they get with programming and I've made numerous attempts to get this working without success. Could someone point me in the right direction? I didn't put any attempts in here because I felt like they were completely off and didn't want to muddy the waters..
from tkinter import *
import tkinter.messagebox as box
import os, subprocess
window = Tk()
window.title( 'PowerShell Script' )
frame = Frame(window)
fldrPath = "\\\\myComputer\share\Power Shell\ps"
listbox = Listbox(frame)
for name in os.listdir(fldrPath):
listbox.insert('end', name)
def selection():
fileList = listbox.curselection()
for file in fileList:
subprocess.Popen(["powershell.exe", '-ExecutionPolicy',
'Unrestricted', '-File', fldrPath + '\\' +
listbox.get(file)], stdout=file_object)
# Use this in selection function as a stdout
file_object = open('c:\\result.txt', 'w')
output = Text(window, width=75, height=6, wrap=WORD, background="white")
btn = Button(frame, text='Run Script', command=selection)
btn.pack(side=RIGHT, padx=5)
listbox.pack(side=LEFT)
frame.pack(padx=30, pady=30)
output.pack(fill=BOTH, expand=1, padx=5, pady=5)
window.mainloop()