开发了一个使用msbuild生成项目的脚本。我用wxpython开发了GUI,wxpython有一个按钮,当用户单击该按钮时,将使用msbuild生成一个项目。现在,我想在用户单击该按钮时打开一个状态窗口,显示命令提示符和命令提示符中显示的所有输出,即将命令提示符输出重定向到用户GUI状态窗口。我的构建脚本是
def build(self,projpath)
arg1 = '/t:Rebuild'
arg2 = '/p:Configuration=Release'
arg3 = '/p:Platform=x86'
p = subprocess.call([self.msbuild,projpath,arg1,arg2,arg3])
if p==1:
return False
return True
我做了一个如下的改变,它确实对我有用。在
实际上,几年前我在我的博客上写过这篇文章,我在博客中创建了一个脚本,将ping和traceroute重定向到我的wxPython应用程序:http://www.blog.pythonlibrary.org/2010/06/05/python-running-ping-traceroute-and-more/
基本上,您创建了一个简单的类来重定向stdout并将其传递给TextCtrl的实例。最后看起来像这样:
当我编写ping命令时,我这样做了:
^{pr2}$主要要看的是子进程调用中的stdout参数和wx.产量()也很重要。产量允许文本“打印”(即重定向)到标准输出。没有它,文本在命令完成之前不会显示。我希望这一切都有道理。在
相关问题 更多 >
编程相关推荐