util/ProcessLogger.py
changeset 3897 fc3621302cfe
parent 3892 1675b5533e9e
child 3965 6c3469588c12
equal deleted inserted replaced
3896:df7ce3e1f44d 3897:fc3621302cfe
    26 import os
    26 import os
    27 import sys
    27 import sys
    28 import subprocess
    28 import subprocess
    29 import ctypes
    29 import ctypes
    30 import time
    30 import time
       
    31 import shlex
    31 from threading import Timer, Lock, Thread, Semaphore, Condition
    32 from threading import Timer, Lock, Thread, Semaphore, Condition
    32 import signal
    33 import signal
    33 
    34 
    34 _debug = os.path.exists("BEREMIZ_DEBUG")
    35 _debug = os.path.exists("BEREMIZ_DEBUG")
    35 
    36 
    80                  endlog=None, keyword=None, kill_it=False, cwd=None,
    81                  endlog=None, keyword=None, kill_it=False, cwd=None,
    81                  encoding=None, output_encoding=None, env=None):
    82                  encoding=None, output_encoding=None, env=None):
    82         self.logger = logger
    83         self.logger = logger
    83         if not isinstance(Command, list):
    84         if not isinstance(Command, list):
    84             self.Command_str = Command
    85             self.Command_str = Command
    85             self.Command = []
    86             self.Command = shlex.split(Command)
    86             for i, word in enumerate(Command.replace("'", '"').split('"')):
    87         else:
    87                 if i % 2 == 0:
    88             self.Command = Command
    88                     word = word.strip()
       
    89                     if len(word) > 0:
       
    90                         self.Command.extend(word.split())
       
    91                 else:
       
    92                     self.Command.append(word)
       
    93         else:
       
    94             self.Command = [x if type(x)==str else x.decode() for x in Command]
       
    95             self.Command_str = subprocess.list2cmdline(self.Command)
    89             self.Command_str = subprocess.list2cmdline(self.Command)
    96 
    90 
    97         fsencoding = sys.getfilesystemencoding()
    91         fsencoding = sys.getfilesystemencoding()
    98         self.output_encoding = output_encoding
    92         self.output_encoding = output_encoding
    99 
    93