wxPopen.py
author lbessard
Tue, 02 Oct 2007 18:05:36 +0200
changeset 60 e9667bec7f00
parent 48 6b30cfee163e
child 70 2767bc85aa9a
permissions -rw-r--r--
Test on wx version changed to test on platform
48
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
     1
#!/usr/bin/env python
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
     3
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
     4
#This file is part of Beremiz, a Integrated Development Environment for
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
     5
#programming IEC 61131-3 automates supporting plcopen standard and CanFestival. 
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
     6
#
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
     7
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
     8
#
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
     9
#See COPYING file for copyrights details.
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    10
#
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    11
#This library is free software; you can redistribute it and/or
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    12
#modify it under the terms of the GNU General Public
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    13
#License as published by the Free Software Foundation; either
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    15
#
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    16
#This library is distributed in the hope that it will be useful,
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    19
#General Public License for more details.
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    20
#
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    21
#You should have received a copy of the GNU General Public
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    22
#License along with this library; if not, write to the Free Software
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    24
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    25
#
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    26
# based on wxPopen.py from boa-constructor
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    27
#
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    28
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    29
import time
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    30
from StringIO import StringIO
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    31
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    32
from wxPython.wx import *
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    33
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    34
class ProcessRunnerMix:
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    35
    def __init__(self, input, handler=None):
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    36
        if handler is None:
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    37
            handler = self
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    38
        self.handler = handler    
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    39
        EVT_IDLE(handler, self.OnIdle)
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    40
        EVT_END_PROCESS(handler, -1, self.OnProcessEnded)
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    41
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    42
        input.reverse() # so we can pop
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    43
        self.input = input
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    44
        
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    45
        self.reset()
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    46
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    47
    def reset(self):
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    48
        self.process = None
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    49
        self.pid = -1
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    50
        self.output = []
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    51
        self.errors = []
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    52
        self.inputStream = None
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    53
        self.errorStream = None
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    54
        self.outputStream = None
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    55
        self.outputFunc = None
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    56
        self.errorsFunc = None
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    57
        self.finishedFunc = None
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    58
        self.finished = false
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    59
        self.responded = false
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    60
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    61
    def execute(self, cmd):
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    62
        self.process = wxProcess(self.handler)
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    63
        self.process.Redirect()
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    64
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    65
        self.pid = wxExecute(cmd, wxEXEC_NOHIDE, self.process)
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    66
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    67
        self.inputStream = self.process.GetOutputStream()
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    68
        self.errorStream = self.process.GetErrorStream()
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    69
        self.outputStream = self.process.GetInputStream()
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    70
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    71
        #self.OnIdle()
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    72
        wxWakeUpIdle()
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    73
    
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    74
    def setCallbacks(self, output, errors, finished):
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    75
        self.outputFunc = output
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    76
        self.errorsFunc = errors
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    77
        self.finishedFunc = finished
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    78
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    79
    def detach(self):
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    80
        if self.process is not None:
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    81
            self.process.CloseOutput()
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    82
            self.process.Detach()
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    83
            self.process = None
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    84
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    85
    def kill(self):
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    86
        if self.process is not None:
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    87
            self.process.CloseOutput()
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    88
            if wxProcess_Kill(self.pid, wxSIGTERM) != wxKILL_OK:
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    89
                wxProcess_Kill(self.pid, wxSIGKILL)
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    90
            self.process = None
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    91
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    92
    def updateStream(self, stream, data):
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    93
        if stream and stream.CanRead():
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    94
            if not self.responded:
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    95
                self.responded = true
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    96
            text = stream.read()
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    97
            data.append(text)
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    98
            return text
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
    99
        else:
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   100
            return None
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   101
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   102
    def updateInpStream(self, stream, input):
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   103
        if stream and input:
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   104
            line = input.pop()
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   105
            stream.write(line)
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   106
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   107
    def updateErrStream(self, stream, data):
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   108
        return self.updateStream(stream, data)
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   109
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   110
    def updateOutStream(self, stream, data):
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   111
        return self.updateStream(stream, data)
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   112
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   113
    def OnIdle(self, event=None):
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   114
        if self.process is not None:
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   115
            self.updateInpStream(self.inputStream, self.input)
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   116
            e = self.updateErrStream(self.errorStream, self.errors)
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   117
            if e is not None and self.errorsFunc is not None:
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   118
                wxCallAfter(self.errorsFunc, e)
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   119
            o = self.updateOutStream(self.outputStream, self.output)
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   120
            if o is not None and self.outputFunc is not None:
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   121
                wxCallAfter(self.outputFunc, o)
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   122
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   123
            #wxWakeUpIdle()
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   124
            #time.sleep(0.001)
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   125
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   126
    def OnProcessEnded(self, event):
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   127
        self.OnIdle()
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   128
        pid,exitcode = event.GetPid(), event.GetExitCode()
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   129
        if self.process:
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   130
            self.process.Destroy()
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   131
            self.process = None
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   132
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   133
        self.finished = true
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   134
        
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   135
        # XXX doesn't work ???
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   136
        #self.handler.Disconnect(-1, wxEVT_IDLE)
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   137
        
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   138
        if self.finishedFunc:
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   139
            wxCallAfter(self.finishedFunc, pid, exitcode)
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   140
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   141
class ProcessRunner(wxEvtHandler, ProcessRunnerMix):
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   142
    def __init__(self, input):
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   143
        wxEvtHandler.__init__(self)
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   144
        ProcessRunnerMix.__init__(self, input)
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   145
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   146
def wxPopen3(cmd, input, output, errors, finish, handler=None):
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   147
    p = ProcessRunnerMix(input, handler)
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   148
    p.setCallbacks(output, errors, finish)
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   149
    p.execute(cmd)
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   150
    return p
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   151
    
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff changeset
   152