wxpython - Read a command prompt output in a separate window in python -
i have python script builds solution file using msbuild on windows system.i want show command prompt output when build process running.my code looks below
def build(self,projpath): if not os.path.isfile(self.msbuild): raise exception('msbuild.exe not found. path=' + self.msbuild) arg1 = '/t:rebuild' arg2 = '/p:configuration=release' p = subprocess.call([self.msbuild,projpath,arg1,arg2]) print p if p==1: return false return true
i able build file, need show build status in separate gui(status window).i tried lot redirect command prompt output file , read file but, not make it. tried below command,
subprocess.check_output('subprocess.call([self.msbuild,projpath,arg1,arg2])', shell=false) > 'c:\tmp\file.txt'
can let me know how can show outputs command prompt in status window(a gui using wxpython) when run script?
i did when wanted capture traceroute , ping commands wxpython. wrote in tutorial: http://www.blog.pythonlibrary.org/2010/06/05/python-running-ping-traceroute-and-more/
first of you'll need redirect stdout, goes this:
redir=redirecttext(log) sys.stdout=redir
where redirecttext special class accepts wx.textctrl argument. see below:
class redirecttext(object): def __init__(self,awxtextctrl): self.out=awxtextctrl def write(self,string): self.out.writetext(string)
and here's example of ping command:
proc = subprocess.popen("ping %s" % ip, shell=true, stdout=subprocess.pipe) print while true: line = proc.stdout.readline() wx.yield() if line.strip() == "": pass else: print line.strip() if not line: break proc.wait()
so need run subprocess , use readline function grab data output. print output stdout redirected text control. wx.yield() call allow text control updated in real time. otherwise, updated after subprocess finished.
Comments
Post a Comment