1.1 --- a/OpenSecurity/bin/cygwin.py Wed Feb 19 11:30:28 2014 +0100
1.2 +++ b/OpenSecurity/bin/cygwin.py Fri Feb 21 11:04:04 2014 +0100
1.3 @@ -38,7 +38,7 @@
1.4 import sys
1.5 import _winreg
1.6 from subprocess import Popen, PIPE, call, STARTUPINFO, _subprocess
1.7 -
1.8 +import threading
1.9 # local
1.10 from environment import Environment
1.11 from opensecurity_util import logger, setupLogger, OpenSecurityException
1.12 @@ -119,30 +119,34 @@
1.13 def cmd():
1.14 return Cygwin.win_cmd
1.15
1.16 + executeLock = threading.Lock()
1.17 #executes command on host system
1.18 @staticmethod
1.19 def execute(program, arguments, wait_return=True, window = False):
1.20 - _startupinfo = STARTUPINFO()
1.21 - if not window:
1.22 - _startupinfo.dwFlags |= _subprocess.STARTF_USESHOWWINDOW
1.23 - _startupinfo.wShowWindow = _subprocess.SW_HIDE
1.24 -
1.25 - logger.debug('trying to launch: ' + program + ' ' + ''.join(arguments))
1.26 - try:
1.27 - process = Popen(executable=program, args=' ' + arguments, startupinfo = _startupinfo, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell = False)
1.28 - logger.debug('Launched: ' + program + ' ' + ''.join(arguments))
1.29 - if not wait_return:
1.30 - return [0, 'working in background', '']
1.31 - result = process.wait()
1.32 - res_stdout = process.stdout.read();
1.33 - res_stderr = process.stderr.read();
1.34 - if res_stdout != "":
1.35 - logger.debug(res_stdout)
1.36 - if res_stderr != "":
1.37 - logger.debug(res_stderr)
1.38 - except:
1.39 - logger.error('Failed to execute cygwin command.\n\tcommand=' + program + ' ' + ''.join(arguments) + '\n')
1.40 - #TODO: throw exception
1.41 + if Cygwin.executeLock.acquire(True):
1.42 + _startupinfo = STARTUPINFO()
1.43 + if not window:
1.44 + _startupinfo.dwFlags |= _subprocess.STARTF_USESHOWWINDOW
1.45 + _startupinfo.wShowWindow = _subprocess.SW_HIDE
1.46 +
1.47 + #logger.debug('trying to launch: ' + program + ' ' + ''.join(arguments))
1.48 + try:
1.49 + process = Popen(executable=program, args=' ' + arguments, startupinfo = _startupinfo, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell = False)
1.50 + logger.debug('Launched: ' + program + ' ' + ''.join(arguments))
1.51 + if not wait_return:
1.52 + return [0, 'working in background', '']
1.53 + result = process.wait()
1.54 + res_stdout = process.stdout.read();
1.55 + res_stderr = process.stderr.read();
1.56 + #if res_stdout != "":
1.57 + # logger.debug(res_stdout)
1.58 + #if res_stderr != "":
1.59 + # logger.debug(res_stderr)
1.60 + except:
1.61 + logger.error('Failed to execute cygwin command.\n\tcommand=' + program + ' ' + ''.join(arguments) + '\n')
1.62 + #TODO: throw exception
1.63 +
1.64 + Cygwin.executeLock.release()
1.65 return result, res_stdout, res_stderr
1.66
1.67 @staticmethod