@@ -86,25 +86,32 @@ def _run_command__generic(self, cmd, shell, input, stdin, stdout, stderr, get_pr
8686 if not get_process :
8787 input_prepared = Helpers .PrepareProcessInput (input , encoding ) # throw
8888
89+ assert input_prepared is None or (type (input_prepared ) == bytes ) # noqa: E721
90+
8991 process = subprocess .Popen (
9092 cmd ,
9193 shell = shell ,
9294 stdin = stdin or subprocess .PIPE if input is not None else None ,
9395 stdout = stdout or subprocess .PIPE ,
9496 stderr = stderr or subprocess .PIPE ,
9597 )
98+ assert not (process is None )
9699 if get_process :
97100 return process , None , None
98101 try :
99102 output , error = process .communicate (input = input_prepared , timeout = timeout )
100- if encoding :
101- output = output .decode (encoding )
102- error = error .decode (encoding )
103- return process , output , error
104103 except subprocess .TimeoutExpired :
105104 process .kill ()
106105 raise ExecUtilException ("Command timed out after {} seconds." .format (timeout ))
107106
107+ assert type (output ) == bytes # noqa: E721
108+ assert type (error ) == bytes # noqa: E721
109+
110+ if encoding :
111+ output = output .decode (encoding )
112+ error = error .decode (encoding )
113+ return process , output , error
114+
108115 def _run_command (self , cmd , shell , input , stdin , stdout , stderr , get_process , timeout , encoding ):
109116 """Execute a command and return the process and its output."""
110117 if os .name == 'nt' and stdout is None : # Windows
0 commit comments