Python popen2.Popen3() Examples

The following are 21 code examples of popen2.Popen3(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module popen2 , or try the search function .
Example #1
Source File: awmstools.py    From DeepLearning_Wavelet-LSTM with MIT License 5 votes vote down vote up
def readProcess(cmd, *args):
    r"""Similar to `os.popen3`, but returns 2 strings (stdin, stdout) and the
    exit code (unlike popen2, exit is 0 if no problems occured (for some
    bizarre reason popen2 returns None... <sigh>).

    FIXME: only works for UNIX; handling of signalled processes.
    """
    import popen2
    BUFSIZE=1024
    import select
    popen = popen2.Popen3((cmd,) + args, capturestderr=True)
    which = {id(popen.fromchild): [],
             id(popen.childerr):  []}
    select = Result(select.select)
    read   = Result(os.read)
    try:
        popen.tochild.close() # XXX make sure we're not waiting forever
        while select([popen.fromchild, popen.childerr], [], []):
            readSomething = False
            for f in select.result[0]:
                while read(f.fileno(), BUFSIZE):
                    which[id(f)].append(read.result)
                    readSomething = True
            if not readSomething:
                break
        out, err = ["".join(which[id(f)])
                    for f in [popen.fromchild, popen.childerr]]
        returncode = popen.wait()

        if os.WIFEXITED(returncode):
            exit = os.WEXITSTATUS(returncode)
        else:
            exit = returncode or 1 # HACK: ensure non-zero
    finally:
        try:
            popen.fromchild.close()
        finally:
            popen.childerr.close()
    return out or "", err or "", exit 
Example #2
Source File: TestCmd.py    From android-xmrig-miner with GNU General Public License v3.0 5 votes vote down vote up
def wait(self, *args, **kw):
                resultcode = apply(popen2.Popen3.wait, (self,)+args, kw)
                if os.WIFEXITED(resultcode):
                    return os.WEXITSTATUS(resultcode)
                elif os.WIFSIGNALED(resultcode):
                    return os.WTERMSIG(resultcode)
                else:
                    return None 
Example #3
Source File: TestCmd.py    From android-xmrig-miner with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, command, **kw):
                if kw.get('stderr') == 'STDOUT':
                    apply(popen2.Popen4.__init__, (self, command, 1))
                else:
                    apply(popen2.Popen3.__init__, (self, command, 1))
                self.stdin = self.tochild
                self.stdout = self.fromchild
                self.stderr = self.childerr 
Example #4
Source File: test_bz2.py    From medicare-demo with Apache License 2.0 5 votes vote down vote up
def decompress(self, data):
            pop = popen2.Popen3("bunzip2", capturestderr=1)
            pop.tochild.write(data)
            pop.tochild.close()
            ret = pop.fromchild.read()
            pop.fromchild.close()
            if pop.wait() != 0:
                ret = bz2.decompress(data)
            return ret 
Example #5
Source File: TestCmd.py    From kawalpemilu2014 with GNU Affero General Public License v3.0 5 votes vote down vote up
def wait(self, *args, **kw):
                resultcode = apply(popen2.Popen3.wait, (self,)+args, kw)
                if os.WIFEXITED(resultcode):
                    return os.WEXITSTATUS(resultcode)
                elif os.WIFSIGNALED(resultcode):
                    return os.WTERMSIG(resultcode)
                else:
                    return None 
Example #6
Source File: TestCmd.py    From kawalpemilu2014 with GNU Affero General Public License v3.0 5 votes vote down vote up
def __init__(self, command, **kw):
                if kw.get('stderr') == 'STDOUT':
                    apply(popen2.Popen4.__init__, (self, command, 1))
                else:
                    apply(popen2.Popen3.__init__, (self, command, 1))
                self.stdin = self.tochild
                self.stdout = self.fromchild
                self.stderr = self.childerr 
Example #7
Source File: TestCmd.py    From gyp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def wait(self, *args, **kw):
                resultcode = popen2.Popen3.wait(self, *args, **kw)
                if os.WIFEXITED(resultcode):
                    return os.WEXITSTATUS(resultcode)
                elif os.WIFSIGNALED(resultcode):
                    return os.WTERMSIG(resultcode)
                else:
                    return None 
Example #8
Source File: TestCmd.py    From gyp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self, command, **kw):
                if kw.get('stderr') == 'STDOUT':
                    popen2.Popen4.__init__(self, command, 1)
                else:
                    popen2.Popen3.__init__(self, command, 1)
                self.stdin = self.tochild
                self.stdout = self.fromchild
                self.stderr = self.childerr 
Example #9
Source File: TestCmd.py    From gyp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def wait(self, *args, **kw):
                resultcode = popen2.Popen3.wait(self, *args, **kw)
                if os.WIFEXITED(resultcode):
                    return os.WEXITSTATUS(resultcode)
                elif os.WIFSIGNALED(resultcode):
                    return os.WTERMSIG(resultcode)
                else:
                    return None 
Example #10
Source File: TestCmd.py    From gyp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self, command, **kw):
                if kw.get('stderr') == 'STDOUT':
                    popen2.Popen4.__init__(self, command, 1)
                else:
                    popen2.Popen3.__init__(self, command, 1)
                self.stdin = self.tochild
                self.stdout = self.fromchild
                self.stderr = self.childerr 
Example #11
Source File: awmstools.py    From DeepLearning_Wavelet-LSTM with MIT License 5 votes vote down vote up
def readProcess(cmd, *args):
    r"""Similar to `os.popen3`, but returns 2 strings (stdin, stdout) and the
    exit code (unlike popen2, exit is 0 if no problems occured (for some
    bizarre reason popen2 returns None... <sigh>).

    FIXME: only works for UNIX; handling of signalled processes.
    """
    import popen2
    BUFSIZE=1024
    import select
    popen = popen2.Popen3((cmd,) + args, capturestderr=True)
    which = {id(popen.fromchild): [],
             id(popen.childerr):  []}
    select = Result(select.select)
    read   = Result(os.read)
    try:
        popen.tochild.close() # XXX make sure we're not waiting forever
        while select([popen.fromchild, popen.childerr], [], []):
            readSomething = False
            for f in select.result[0]:
                while read(f.fileno(), BUFSIZE):
                    which[id(f)].append(read.result)
                    readSomething = True
            if not readSomething:
                break
        out, err = ["".join(which[id(f)])
                    for f in [popen.fromchild, popen.childerr]]
        returncode = popen.wait()

        if os.WIFEXITED(returncode):
            exit = os.WEXITSTATUS(returncode)
        else:
            exit = returncode or 1 # HACK: ensure non-zero
    finally:
        try:
            popen.fromchild.close()
        finally:
            popen.childerr.close()
    return out or "", err or "", exit 
Example #12
Source File: cert.py    From CyberScan with GNU General Public License v3.0 5 votes vote down vote up
def print_chain(l):
    llen = len(l) - 1
    if llen < 0:
        return ""
    c = l[llen]
    llen -= 1
    s = "_ "
    if not c.isSelfSigned():
        s = "_ ... [Missing Root]\n"
    else:
        s += "%s [Self Signed]\n" % c.subject
    i = 1
    while (llen != -1):
        c = l[llen]
        s += "%s\_ %s" % (" "*i, c.subject)
        if llen != 0:
            s += "\n"
        i += 2
        llen -= 1
    print s

# import popen2
# a=popen2.Popen3("openssl crl -text -inform DER -noout ", capturestderr=True)
# a.tochild.write(open("samples/klasa1.crl").read())
# a.tochild.close()
# a.poll() 
Example #13
Source File: awmstools.py    From DeepLearning_Wavelet-LSTM with MIT License 5 votes vote down vote up
def readProcess(cmd, *args):
    r"""Similar to `os.popen3`, but returns 2 strings (stdin, stdout) and the
    exit code (unlike popen2, exit is 0 if no problems occured (for some
    bizarre reason popen2 returns None... <sigh>).

    FIXME: only works for UNIX; handling of signalled processes.
    """
    import popen2
    BUFSIZE=1024
    import select
    popen = popen2.Popen3((cmd,) + args, capturestderr=True)
    which = {id(popen.fromchild): [],
             id(popen.childerr):  []}
    select = Result(select.select)
    read   = Result(os.read)
    try:
        popen.tochild.close() # XXX make sure we're not waiting forever
        while select([popen.fromchild, popen.childerr], [], []):
            readSomething = False
            for f in select.result[0]:
                while read(f.fileno(), BUFSIZE):
                    which[id(f)].append(read.result)
                    readSomething = True
            if not readSomething:
                break
        out, err = ["".join(which[id(f)])
                    for f in [popen.fromchild, popen.childerr]]
        returncode = popen.wait()

        if os.WIFEXITED(returncode):
            exit = os.WEXITSTATUS(returncode)
        else:
            exit = returncode or 1 # HACK: ensure non-zero
    finally:
        try:
            popen.fromchild.close()
        finally:
            popen.childerr.close()
    return out or "", err or "", exit 
Example #14
Source File: awmstools.py    From DeepLearning_Wavelet-LSTM with MIT License 5 votes vote down vote up
def readProcess(cmd, *args):
    r"""Similar to `os.popen3`, but returns 2 strings (stdin, stdout) and the
    exit code (unlike popen2, exit is 0 if no problems occured (for some
    bizarre reason popen2 returns None... <sigh>).

    FIXME: only works for UNIX; handling of signalled processes.
    """
    import popen2
    BUFSIZE=1024
    import select
    popen = popen2.Popen3((cmd,) + args, capturestderr=True)
    which = {id(popen.fromchild): [],
             id(popen.childerr):  []}
    select = Result(select.select)
    read   = Result(os.read)
    try:
        popen.tochild.close() # XXX make sure we're not waiting forever
        while select([popen.fromchild, popen.childerr], [], []):
            readSomething = False
            for f in select.result[0]:
                while read(f.fileno(), BUFSIZE):
                    which[id(f)].append(read.result)
                    readSomething = True
            if not readSomething:
                break
        out, err = ["".join(which[id(f)])
                    for f in [popen.fromchild, popen.childerr]]
        returncode = popen.wait()

        if os.WIFEXITED(returncode):
            exit = os.WEXITSTATUS(returncode)
        else:
            exit = returncode or 1 # HACK: ensure non-zero
    finally:
        try:
            popen.fromchild.close()
        finally:
            popen.childerr.close()
    return out or "", err or "", exit 
Example #15
Source File: awmstools.py    From DeepLearning_Wavelet-LSTM with MIT License 5 votes vote down vote up
def readProcess(cmd, *args):
    r"""Similar to `os.popen3`, but returns 2 strings (stdin, stdout) and the
    exit code (unlike popen2, exit is 0 if no problems occured (for some
    bizarre reason popen2 returns None... <sigh>).

    FIXME: only works for UNIX; handling of signalled processes.
    """
    import popen2
    BUFSIZE=1024
    import select
    popen = popen2.Popen3((cmd,) + args, capturestderr=True)
    which = {id(popen.fromchild): [],
             id(popen.childerr):  []}
    select = Result(select.select)
    read   = Result(os.read)
    try:
        popen.tochild.close() # XXX make sure we're not waiting forever
        while select([popen.fromchild, popen.childerr], [], []):
            readSomething = False
            for f in select.result[0]:
                while read(f.fileno(), BUFSIZE):
                    which[id(f)].append(read.result)
                    readSomething = True
            if not readSomething:
                break
        out, err = ["".join(which[id(f)])
                    for f in [popen.fromchild, popen.childerr]]
        returncode = popen.wait()

        if os.WIFEXITED(returncode):
            exit = os.WEXITSTATUS(returncode)
        else:
            exit = returncode or 1 # HACK: ensure non-zero
    finally:
        try:
            popen.fromchild.close()
        finally:
            popen.childerr.close()
    return out or "", err or "", exit 
Example #16
Source File: awmstools.py    From DeepLearning_Wavelet-LSTM with MIT License 5 votes vote down vote up
def readProcess(cmd, *args):
    r"""Similar to `os.popen3`, but returns 2 strings (stdin, stdout) and the
    exit code (unlike popen2, exit is 0 if no problems occured (for some
    bizarre reason popen2 returns None... <sigh>).

    FIXME: only works for UNIX; handling of signalled processes.
    """
    import popen2
    BUFSIZE=1024
    import select
    popen = popen2.Popen3((cmd,) + args, capturestderr=True)
    which = {id(popen.fromchild): [],
             id(popen.childerr):  []}
    select = Result(select.select)
    read   = Result(os.read)
    try:
        popen.tochild.close() # XXX make sure we're not waiting forever
        while select([popen.fromchild, popen.childerr], [], []):
            readSomething = False
            for f in select.result[0]:
                while read(f.fileno(), BUFSIZE):
                    which[id(f)].append(read.result)
                    readSomething = True
            if not readSomething:
                break
        out, err = ["".join(which[id(f)])
                    for f in [popen.fromchild, popen.childerr]]
        returncode = popen.wait()

        if os.WIFEXITED(returncode):
            exit = os.WEXITSTATUS(returncode)
        else:
            exit = returncode or 1 # HACK: ensure non-zero
    finally:
        try:
            popen.fromchild.close()
        finally:
            popen.childerr.close()
    return out or "", err or "", exit 
Example #17
Source File: awmstools.py    From DeepLearning_Wavelet-LSTM with MIT License 5 votes vote down vote up
def readProcess(cmd, *args):
    r"""Similar to `os.popen3`, but returns 2 strings (stdin, stdout) and the
    exit code (unlike popen2, exit is 0 if no problems occured (for some
    bizarre reason popen2 returns None... <sigh>).

    FIXME: only works for UNIX; handling of signalled processes.
    """
    import popen2
    BUFSIZE=1024
    import select
    popen = popen2.Popen3((cmd,) + args, capturestderr=True)
    which = {id(popen.fromchild): [],
             id(popen.childerr):  []}
    select = Result(select.select)
    read   = Result(os.read)
    try:
        popen.tochild.close() # XXX make sure we're not waiting forever
        while select([popen.fromchild, popen.childerr], [], []):
            readSomething = False
            for f in select.result[0]:
                while read(f.fileno(), BUFSIZE):
                    which[id(f)].append(read.result)
                    readSomething = True
            if not readSomething:
                break
        out, err = ["".join(which[id(f)])
                    for f in [popen.fromchild, popen.childerr]]
        returncode = popen.wait()

        if os.WIFEXITED(returncode):
            exit = os.WEXITSTATUS(returncode)
        else:
            exit = returncode or 1 # HACK: ensure non-zero
    finally:
        try:
            popen.fromchild.close()
        finally:
            popen.childerr.close()
    return out or "", err or "", exit 
Example #18
Source File: awmstools.py    From DeepLearning_Wavelet-LSTM with MIT License 5 votes vote down vote up
def readProcess(cmd, *args):
    r"""Similar to `os.popen3`, but returns 2 strings (stdin, stdout) and the
    exit code (unlike popen2, exit is 0 if no problems occured (for some
    bizarre reason popen2 returns None... <sigh>).

    FIXME: only works for UNIX; handling of signalled processes.
    """
    import popen2
    BUFSIZE=1024
    import select
    popen = popen2.Popen3((cmd,) + args, capturestderr=True)
    which = {id(popen.fromchild): [],
             id(popen.childerr):  []}
    select = Result(select.select)
    read   = Result(os.read)
    try:
        popen.tochild.close() # XXX make sure we're not waiting forever
        while select([popen.fromchild, popen.childerr], [], []):
            readSomething = False
            for f in select.result[0]:
                while read(f.fileno(), BUFSIZE):
                    which[id(f)].append(read.result)
                    readSomething = True
            if not readSomething:
                break
        out, err = ["".join(which[id(f)])
                    for f in [popen.fromchild, popen.childerr]]
        returncode = popen.wait()

        if os.WIFEXITED(returncode):
            exit = os.WEXITSTATUS(returncode)
        else:
            exit = returncode or 1 # HACK: ensure non-zero
    finally:
        try:
            popen.fromchild.close()
        finally:
            popen.childerr.close()
    return out or "", err or "", exit 
Example #19
Source File: awmstools.py    From DeepLearning_Wavelet-LSTM with MIT License 5 votes vote down vote up
def readProcess(cmd, *args):
    r"""Similar to `os.popen3`, but returns 2 strings (stdin, stdout) and the
    exit code (unlike popen2, exit is 0 if no problems occured (for some
    bizarre reason popen2 returns None... <sigh>).

    FIXME: only works for UNIX; handling of signalled processes.
    """
    import popen2
    BUFSIZE=1024
    import select
    popen = popen2.Popen3((cmd,) + args, capturestderr=True)
    which = {id(popen.fromchild): [],
             id(popen.childerr):  []}
    select = Result(select.select)
    read   = Result(os.read)
    try:
        popen.tochild.close() # XXX make sure we're not waiting forever
        while select([popen.fromchild, popen.childerr], [], []):
            readSomething = False
            for f in select.result[0]:
                while read(f.fileno(), BUFSIZE):
                    which[id(f)].append(read.result)
                    readSomething = True
            if not readSomething:
                break
        out, err = ["".join(which[id(f)])
                    for f in [popen.fromchild, popen.childerr]]
        returncode = popen.wait()

        if os.WIFEXITED(returncode):
            exit = os.WEXITSTATUS(returncode)
        else:
            exit = returncode or 1 # HACK: ensure non-zero
    finally:
        try:
            popen.fromchild.close()
        finally:
            popen.childerr.close()
    return out or "", err or "", exit 
Example #20
Source File: cert.py    From mptcp-abuse with GNU General Public License v2.0 5 votes vote down vote up
def print_chain(l):
    llen = len(l) - 1
    if llen < 0:
        return ""
    c = l[llen]
    llen -= 1
    s = "_ "
    if not c.isSelfSigned():
        s = "_ ... [Missing Root]\n"
    else:
        s += "%s [Self Signed]\n" % c.subject
    i = 1
    while (llen != -1):
        c = l[llen]
        s += "%s\_ %s" % (" "*i, c.subject)
        if llen != 0:
            s += "\n"
        i += 2
        llen -= 1
    print s

# import popen2
# a=popen2.Popen3("openssl crl -text -inform DER -noout ", capturestderr=True)
# a.tochild.write(open("samples/klasa1.crl").read())
# a.tochild.close()
# a.poll() 
Example #21
Source File: cert.py    From CVE-2016-6366 with MIT License 5 votes vote down vote up
def print_chain(l):
    llen = len(l) - 1
    if llen < 0:
        return ""
    c = l[llen]
    llen -= 1
    s = "_ "
    if not c.isSelfSigned():
        s = "_ ... [Missing Root]\n"
    else:
        s += "%s [Self Signed]\n" % c.subject
    i = 1
    while (llen != -1):
        c = l[llen]
        s += "%s\_ %s" % (" "*i, c.subject)
        if llen != 0:
            s += "\n"
        i += 2
        llen -= 1
    print s

# import popen2
# a=popen2.Popen3("openssl crl -text -inform DER -noout ", capturestderr=True)
# a.tochild.write(open("samples/klasa1.crl").read())
# a.tochild.close()
# a.poll()