I had a similar issue.My app has an output window where the script results
appear as it is running. Unfortunately I could not find a clean way to do
it. So I resorted to the somewhat ugly method shown below. If anyone knows
how to tell when a script is done, I would like to know.
(You may get some annoying word wrap since there are several long lines
here)
def RunScriptShowOutput(self, cmdline, title):
"""Run the script via the cmdline provided. Route output to the
output page."""
self.SetCursor(wxStockCursor(wxCURSOR_WAIT))
resOutErr, resStdin = popen2.popen4(cmdline)
self.SetSelection(PAGE_OUTPUTNUM)
self.outputpage.ClearAll()
self.outputpage.AppendLines('Output from %s...\n' % title)
try:
blankline = 0
while 1:
wxYield()
line = resOutErr.readline()
self.outputpage.AppendLines(line)
if line == None or line == '':
blankline += 1
#To Do: find out how to tell if script is done running;
until then, rely on the hack below.
#A script may put out a blank line or 2, but rarely lots of
blank lines. So when we have seen
#30 blank lines, we assume script is done and terminate the
loop
if blankline > 30:
#print 'breaking at blankline count'
break
inret = resStdin.close()
outret = resOutErr.close()
if outret == None:
outret = 0
exitline = '\n==> Exit code: %d' % outret
self.outputpage.AppendLines(exitline)
self.SetCursor(wxStockCursor(wxCURSOR_ARROW))
------- -------- --------
This code is executed when the user selects "Run" from a menu:
def OnScriptRun(self, event):
"""Run the currently-active script."""
doc = self.scriptnbk.GetActiveDoc()
if doc == None:
dlg = wxMessageDialog(self, 'Error: Unable to run script.\nNo
active document.',
'Cannot Run Script', wxOK)
dlg.ShowModal()
dlg.Destroy()
return
#get the name of the current script
cwd = os.getcwd() #save where we are now
fullpath = self.scriptnbk.GetActiveDocTitle(1)
if fullpath == '' or fullpath == None:
dlg = wxMessageDialog(self, 'Error: Unable to run script.\nCould
not find the path for the active document.',
'Cannot Run Script', wxOK)
dlg.ShowModal()
dlg.Destroy()
return
self.scriptnbk.SaveDoc(doc) #save before running
os.chdir(os.path.dirname(fullpath)) #keep Python happy, in case
script not in sys.path
if wxPlatform == '__WXMSW__':
cmd = 'pythonw -u %s' % os.path.basename(fullpath)
else:
cmd = 'python -u %s' % os.path.basename(fullpath)
#print 'cmd=', cmd
self.AdjustNBSashPosition()
self.nb.RunScriptShowOutput(cmd, os.path.basename(fullpath))
os.chdir(cwd) #restore previous location
···
-----Original Message-----
From: Andrew Perella [mailto:ajp@eutechnyx.com]
Sent: Thursday, October 04, 2001 4:34 AM
To: wxpython-users@lists.wxwindows.org
Subject: RE: [wxPython] wxExecute
I have tried popen3 but iot does not give the results back asynchronously. I
want to monmitor the output as it is running. Is this possible?
On a related note I get huge (and I mean huge) memory leaks (not detected by
wxwindows exit) if I use wxExecute, but not if I use popen3
Cheers,
A.
-----Original Message-----
From: wxpython-users-admin@lists.wxwindows.org
[mailto:wxpython-users-admin@lists.wxwindows.org]On Behalf Of Joshua
Rosen
Sent: 04 October 2001 05:32
To: wxpython-users@lists.wxwindows.org
Subject: Re: [wxPython] wxExecuteAndrew Perella wrote:
>
> Has anyone had any difficulties using wxExecute rather than os.system()?
>
> I decided to use wxExecute since os.system does not seem to
asynchronously
> return the stream outputs.Try the os.popen* functions.
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users_____________________________________________________________________
This e-mail is confidential and may be privileged. It may be
read, copied and used only by the intended recipient. No
communication sent by e-mail to or from Eutechnyx is intended to
give rise to contractual or other legal liability, apart from
liability which cannot be excluded under English law.This message has been checked for all known viruses by Star
Internet delivered through the MessageLabs Virus Control Centre.www.eutechnyx.com Eutechnyx Limited. Registered in England No: 2172322
_____________________________________________________________________
This e-mail is confidential and may be privileged. It may be read, copied
and used only by the intended recipient. No communication sent by e-mail to
or from Eutechnyx is intended to give rise to contractual or other legal
liability, apart from liability which cannot be excluded under English law.
This message has been checked for all known viruses by Star Internet
delivered through the MessageLabs Virus Control Centre.
www.eutechnyx.com Eutechnyx Limited. Registered in England No: 2172322
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users