简体   繁体   English

使用wxpython将终端输出传递给GUI

[英]pass terminal output to GUI using wxpython

Hi all i am using python 2.7 and for GUI wxpython, in linux environment. 大家好,我在Linux环境中使用python 2.7和GUI wxpython。 I wants to redirect output from terminal to Message box, how it will happen? 我想将输出从终端重定向到消息框,它将如何发生? My code is: 我的代码是:

 p = subprocess.call(" grep "Wanted" .filename | awk '{print $2}' | cut -c11-20", shell=True)

This will give proper output in terminal,but when i call it in message box it shows "0". 这将在终端中提供正确的输出,但是当我在消息框中调用它时显示“ 0”。

 wx.MessageBox(" file name:'%s' % (str(p)), "info")

how to print those which are displayed in terminal , i am newbie to python world and have less knowledge in python. 如何打印在终端中显示的内容,我是python world的新手,对python的了解较少。 Searched for answer but couldn't any answer.so dropping here for solution and guidance. 搜索了答案,但找不到任何答案。因此请在此处寻求解决方案和指导。 Thanks in advance 提前致谢

Might be prefered/simpler to use Popen (But I rarly use subprocess.call so I do no know). 可能更喜欢/更简单地使用Popen(但是我很少使用subprocess.call,所以我不知道)。 But you example should work fine (with the mentioned fix from Ashwini Chaudhary), from what I see. 但是从我的角度来看,您的示例应该可以正常工作(使用Ashwini Chaudhary提到的修复程序)。

import subprocess
import wx

def main():
    p = subprocess.Popen(['ls', '-a'], stdout = subprocess.PIPE)
    text = p.stdout.readlines()
    text = "".join(text)

    wx.MessageBox("file names:\n%s" % text, "info")

if __name__ == '__main__':
    app = wx.PySimpleApp()
    main()

Anyways: Any reason to involve Bash, cant python do the same? 无论如何:涉及Bash的任何理由,python不能做到吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM