#NEWLINE# def pipe_commands( cmds , extra_env = None , show_stderr = False , show_last_stdout = False ) : #NEWLINE# #INDENT# '\n    Executes the list of commands piping each one into the next.\n    ' #NEWLINE# env = ( extend_env ( extra_env ) if processes else None ) #NEWLINE# env_str = ( ( get_env_str ( extra_env ) + ' ' ) if extra_env else '' ) #NEWLINE# cmd_strs = [ ( env_str + ' ' . join ( cmd ) ) for cmd in cmds ] #NEWLINE# logger . info ( 'Running `{0}`' . format ( ' | ' . join ( cmd_strs ) ) ) #NEWLINE# with open ( '/dev/null' , 'w' ) as NULL : #NEWLINE# #INDENT# processes = [ ] #NEWLINE# last_i = ( len ( cmds ) - 1 ) #NEWLINE# for ( i , ( cmd_str , cmd ) ) in enumerate ( zip ( cmd_strs , cmds ) ) : #NEWLINE# #INDENT# if ( i == last_i ) : #NEWLINE# #INDENT# p_stdout = ( None if show_last_stdout else NULL ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# p_stdout = PIPE #NEWLINE# #UNINDENT# p_stdin = ( processes [ ( - 1 ) ] [ 1 ] . stdout if processes else None ) #NEWLINE# p_stderr = ( None if show_stderr else NULL ) #NEWLINE# p = Popen ( cmd , env = env , stdout = p_stdout , stdin = p_stdin , stderr = p_stderr ) #NEWLINE# processes . append ( ( cmd_str , p ) ) #NEWLINE# #UNINDENT# error = False #NEWLINE# for ( cmd_str , p ) in processes : #NEWLINE# #INDENT# if p . stdout : #NEWLINE# #INDENT# p . stdout . close ( ) #NEWLINE# #UNINDENT# if ( p . wait ( ) != 0 ) : #NEWLINE# #INDENT# error = True #NEWLINE# #UNINDENT# #UNINDENT# if error : #NEWLINE# #INDENT# raise CalledProcessError ( cmd = cmd_str , returncode = p . returncode )