#NEWLINE# def run_command( cmd , data , location , chw ) : #NEWLINE# #INDENT# "\n        Runs command specified in 'cmd' and provides the input with the given data.\n        Also if there is a location it will be appended to the end of command.\n    " #NEWLINE# output = None #NEWLINE# cwd = os . getcwd ( ) #NEWLINE# if ( ( location is not None ) and ( chw is True ) ) : #NEWLINE# #INDENT# cwd = location #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( location is not None ) and ( chw is False ) ) : #NEWLINE# #INDENT# cmd = '{0} {1}' . format ( cmd , location ) #NEWLINE# #UNINDENT# #UNINDENT# r = Popen ( shlex . split ( cmd ) , stdout = PIPE , stdin = PIPE , stderr = PIPE , cwd = cwd ) #NEWLINE# if ( data is None ) : #NEWLINE# #INDENT# output = r . communicate ( ) [ 0 ] . decode ( 'utf-8' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# output = r . communicate ( input = data ) [ 0 ] #NEWLINE# #UNINDENT# return output