(self, cmd1, cmd2, **kwargs)
return not (proc_1.returncode or proc_2.returncode)
Pipe two shell commands
Pipe two shell commands
Pipe two shell commands
def pipe(self, cmd1, cmd2, **kwargs):
        """Pipe two shell commands"""
        path = Config.conf["root_path"] + ":" + os.getenv("PATH", "")
        if not cmd1[0].startswith("/"):
            cmd1[0] = self.find_inpath(cmd1[0], path)
        if not cmd2[0].startswith("/"):
            cmd2[0] = self.find_inpath(cmd2[0], path)
        try:
            proc_1 = subprocess.Popen(cmd1, stderr=Msg.chlderr, shell=False,
                                      stdout=subprocess.PIPE, **kwargs)
        except (OSError, ValueError):
            return False
        try:
            proc_2 = subprocess.Popen(cmd2, stderr=Msg.chlderr, shell=False,
                                      stdin=proc_1.stdout)
        except (OSError, ValueError):
            proc_1.kill()
            return False
        while proc_1.returncode is None or proc_2.returncode is None:
            proc_1.wait()
            proc_2.wait()
        return not (proc_1.returncode or proc_2.returncode)
def pipe ( self , cmd1 , cmd2 , * * kwargs ) : path = Config . conf [ "root_path" ] + ":" + os . getenv ( "PATH" , "" ) if not cmd1 [ 0 ] . startswith ( "/" ) : cmd1 [ 0 ] = self . find_inpath ( cmd1 [ 0 ] , path ) if not cmd2 [ 0 ] . startswith ( "/" ) : cmd2 [ 0 ] = self . find_inpath ( cmd2 [ 0 ] , path ) try : proc_1 = subprocess . Popen ( cmd1 , stderr = Msg . chlderr , shell = False , stdout = subprocess . PIPE , * * kwargs ) except ( OSError , ValueError ) : return False try : proc_2 = subprocess . Popen ( cmd2 , stderr = Msg . chlderr , shell = False , stdin = proc_1 . stdout ) except ( OSError , ValueError ) : proc_1 . kill ( ) return False while proc_1 . returncode is None or proc_2 . returncode is None : proc_1 . wait ( ) proc_2 . wait ( ) return not ( proc_1 . returncode or proc_2 . returncode )