Esempio n. 1
0
def detach(cmdargs):
    """
    """
    lg.out(2, "child_process.detach %s" % str(cmdargs))
    try:
        if bpio.Windows():
            import win32process  # @UnresolvedImport
            p = nonblocking.Popen(
                cmdargs,
                shell=False,
                # stdin=subprocess.PIPE,
                # stdout=subprocess.PIPE,
                # stderr=subprocess.PIPE,
                universal_newlines=False,
                creationflags=win32process.CREATE_NO_WINDOW
                | win32process.DETACHED_PROCESS,
                close_fds=True,
            )
        else:
            p = nonblocking.Popen(
                cmdargs,
                shell=False,
                stdin=subprocess.PIPE,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
                universal_newlines=False,
                close_fds=True,
            )
    except:
        lg.out(1, 'child_process.detach ERROR executing: %s' + str(cmdargs))
        lg.exc()
        return None
    return p
Esempio n. 2
0
def pipe(cmdargs):
    """
    Execute a process in different way, create a Pipe to do read/write
    operations with child process.

    See ``lib.nonblocking`` module.
    """
    lg.out(6, "child_process.pipe %s" % str(cmdargs))
    try:
        if bpio.Windows():
            import win32process  # @UnresolvedImport
            p = nonblocking.Popen(
                cmdargs,
                shell=True,
                stdin=subprocess.PIPE,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
                universal_newlines=False,
                creationflags=win32process.CREATE_NO_WINDOW,
            )
        else:
            p = nonblocking.Popen(
                cmdargs,
                shell=False,
                stdin=subprocess.PIPE,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
                universal_newlines=False,
            )
    except:
        lg.out(1, 'child_process.pipe ERROR executing: %s' + str(cmdargs))
        lg.exc()
        return None
    return p
Esempio n. 3
0
def execute_in_shell(cmdargs, base_dir=None):
    global _CurrentProcess
    from system import nonblocking
    import subprocess
    if _Debug:
        lg.out(_DebugLevel,
               'run_upnpc.execute_in_shell: "%s"' % (' '.join(cmdargs)))
    in_shell = True
    if bpio.Mac():
        in_shell = False
    _CurrentProcess = nonblocking.Popen(
        cmdargs,
        shell=in_shell,
        stdin=subprocess.PIPE,
        stdout=subprocess.PIPE,
        stderr=subprocess.STDOUT,
    )
    out_data = _CurrentProcess.communicate()[0]
    returncode = _CurrentProcess.returncode
    if _Debug:
        lg.out(
            _DebugLevel,
            'run_upnpc.execute_in_shell returned: %s and %d bytes output' %
            (returncode, len(out_data)))
    if returncode > 0:
        if _Debug:
            lg.out(_DebugLevel, '\n' + out_data)
    return (out_data, returncode)  # _CurrentProcess
Esempio n. 4
0
def execute_in_shell(cmdargs, base_dir=None):
    global _CurrentProcess
    from system import nonblocking
    import subprocess
    if _Debug:
        lg.out(_DebugLevel,
               'git_proc.execute_in_shell: "%s"' % (' '.join(cmdargs)))
    write2log('EXECUTE in shell: %s, base_dir=%s' % (cmdargs, base_dir))
    _CurrentProcess = nonblocking.Popen(
        cmdargs,
        shell=True,
        cwd=bpio.portablePath(base_dir),
        stdin=subprocess.PIPE,
        stdout=subprocess.PIPE,
        stderr=subprocess.STDOUT,
    )
    result = _CurrentProcess.communicate()
    out_data = result[0]
    err_data = result[1]
    write2log('STDOUT:\n%s\nSTDERR:\n%s\n' % (out_data, err_data))
    returncode = _CurrentProcess.returncode
    if _Debug:
        lg.out(
            _DebugLevel,
            'git_proc.execute_in_shell returned: %s, stdout bytes: %d, stderr bytes: %d'
            % (returncode, len(out_data), len(err_data)))
    return (out_data, err_data, returncode)  # _CurrentProcess
Esempio n. 5
0
def run(Tester):
    global _CurrentProcess
    # lg.out(8, 'localtester.run ' + str(Tester))

    if bpio.isFrozen() and bpio.Windows():
        commandpath = 'bptester.exe'
        cmdargs = [commandpath, Tester]
    else:
        commandpath = 'bptester.py'
        cmdargs = [sys.executable, commandpath, Tester]

    if not os.path.isfile(commandpath):
        lg.out(1, 'localtester.run ERROR %s not found' % commandpath)
        return None

    lg.out(14, 'localtester.run execute: %s' % cmdargs)

    try:
        if bpio.Windows():
            import win32process
            _CurrentProcess = nonblocking.Popen(
                cmdargs,
                shell=False,
                stdin=subprocess.PIPE,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
                universal_newlines=False,
                creationflags=win32process.CREATE_NO_WINDOW,
            )
        else:
            _CurrentProcess = nonblocking.Popen(
                cmdargs,
                shell=False,
                stdin=subprocess.PIPE,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
                universal_newlines=False,
            )
    except:
        lg.out(1, 'localtester.run ERROR executing: %s' % str(cmdargs))
        lg.exc()
        return None
    return _CurrentProcess