def shell(args, wait=True, msg=None):
    """
    Execute the external command and get its exitcode, stdout and stderr.
    """

    # Fix Windows error if passed a string
    if isinstance(args, str):
        args = shlex.split(args, posix=(os.name != "nt"))
        if os.name == "nt":
            args = [arg.replace('/', '\\') for arg in args]

    if wait:
        proc = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE)
        out, err = proc.communicate(input=msg)
        exitcode = proc.returncode
        if exitcode != 0:
            raise IOError(err)
        return out
    else:
        DETACHED_PROCESS = 0x00000008
        proc = Popen(args, creationflags=DETACHED_PROCESS)
def shell ( args , wait = True , msg = None ) : if isinstance ( args , str ) : args = shlex . split ( args , posix = ( os . name != "nt" ) ) if os . name == "nt" : args = [ arg . replace ( '/' , '\\' ) for arg in args ] if wait : proc = Popen ( args , stdin = PIPE , stdout = PIPE , stderr = PIPE ) out , err = proc . communicate ( input = msg ) exitcode = proc . returncode if exitcode != 0 : raise IOError ( err ) return out else : DETACHED_PROCESS = 0x00000008 proc = Popen ( args , creationflags = DETACHED_PROCESS )
Execute the external command and get its exitcode, stdout and stderr.