How to suppress showing of shell windows ?

Hi !

I have a py2exe compiled wx application in Windows.
I call shell commands in my module with this function:

def Cmd(cmd,LogProc,tmpdir=PrgPath):
    outfn='%s/_out.msg'%tmpdir
    errfn='%s/_err.msg'%tmpdir
    post="1>%s 2>%s"%(outfn,errfn)
    cmd2='%s %s'%(cmd,post)
    try:
      LogProc("Command: %s"%cmd2)
      cmd2=Decode(cmd2)
      r=os.system(cmd2)
    except:
      typ,val,tra=sys.exc_info()
      excmsg="\n".join(traceback.format_exception(typ,val,tra))
      return(-1,excmsg)
    f=open(outfn,"r")
    try:
       s1=f.read()
    finally:
       f.close()
    f=open(errfn,"r")
    try:
       s2=f.read()
    finally:
       f.close()
    s="\n".join([s1,s2]).strip()
    os.remove(outfn)
    os.remove(errfn)
    return (r,s)

Results are catched, and I can get every information: the process result code, and result messages too.
Result code is interesting, because if not 0, I can do anything else. And messages in any computers are not same - but this code is equal everytime.
Result messages stored in log, for better error catching, and for mail reporting.

This is working on a server machine. But I want to do same thing in a client.
So I created and compiled a wx wrapper, a simple log shower (progress) window.

But !

In this mode the every command open a shell window while working, and that is very ugly !
Can anyone helps me ? I want to hide these windows, or prevent the showing of them.

Thanks for advance: dd

*From:* "durumdara@mailpont.hu" <durumdara@mailpont.hu>
*To:* wxPython-users@lists.wxwidgets.org
*Date:* Fri, 30 Sep 2005 15:39:31 +0200

Hi !

I have a py2exe compiled wx application in Windows.
I call shell commands in my module with this function:

def Cmd(cmd,LogProc,tmpdir=PrgPath):
    outfn='%s/_out.msg'%tmpdir
    errfn='%s/_err.msg'%tmpdir
    post="1>%s 2>%s"%(outfn,errfn)
    cmd2='%s %s'%(cmd,post)
    try:
      LogProc("Command: %s"%cmd2)
      cmd2=Decode(cmd2)
      r=os.system(cmd2)
    except:
      typ,val,tra=sys.exc_info()
      excmsg="\n".join(traceback.format_exception(typ,val,tra))
      return(-1,excmsg)
    f=open(outfn,"r")
    try:
       s1=f.read()
    finally:
       f.close()
    f=open(errfn,"r")
    try:
       s2=f.read()
    finally:
       f.close()
    s="\n".join([s1,s2]).strip()
    os.remove(outfn)
    os.remove(errfn)
    return (r,s)

Results are catched, and I can get every information: the process
result code, and result messages too.
Result code is interesting, because if not 0, I can do anything else.
And messages in any computers are not same - but this code is equal
everytime.
Result messages stored in log, for better error catching, and for mail
reporting.

This is working on a server machine. But I want to do same thing in a
client.
So I created and compiled a wx wrapper, a simple log shower (progress)
window.

But !

In this mode the every command open a shell window while working, and
that is very ugly !
Can anyone helps me ? I want to hide these windows, or prevent the
showing of them.

Thanks for advance: dd

Instead of using os.system, try using the Python function os.popen, like

  fo = os.popen(command-string, mode='r')
  
This runs the command_string in a new process, without a visible shell
window and also returns stdout to the file object fo - so I think you can
achieve what you are doing with your temporary files by doing something
like

  s = fo.readlines()
  
If os.popen doesn't do everything you need, there are variants os.popen2,
popen3 and popen4 that wrap the stdin, stdout and stderr pipes in
different ways. In Python 2.4 these have been replaced by the single Popen
class in the subprocess module. See:

www.python.org/dev/doc/devel/lib/module-subprocess.html

and

aspn.activestate.com/ASPN/docs/ActivePython/2.4/python/lib/node230.html

Regards,

David Hughes
Forestfield Software
www.foresoft.co.uk