@@ -86,25 +86,32 @@ def _run_command__generic(self, cmd, shell, input, stdin, stdout, stderr, get_pr
86
86
if not get_process :
87
87
input_prepared = Helpers .PrepareProcessInput (input , encoding ) # throw
88
88
89
+ assert input_prepared is None or (type (input_prepared ) == bytes ) # noqa: E721
90
+
89
91
process = subprocess .Popen (
90
92
cmd ,
91
93
shell = shell ,
92
94
stdin = stdin or subprocess .PIPE if input is not None else None ,
93
95
stdout = stdout or subprocess .PIPE ,
94
96
stderr = stderr or subprocess .PIPE ,
95
97
)
98
+ assert not (process is None )
96
99
if get_process :
97
100
return process , None , None
98
101
try :
99
102
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
104
103
except subprocess .TimeoutExpired :
105
104
process .kill ()
106
105
raise ExecUtilException ("Command timed out after {} seconds." .format (timeout ))
107
106
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
+
108
115
def _run_command (self , cmd , shell , input , stdin , stdout , stderr , get_process , timeout , encoding ):
109
116
"""Execute a command and return the process and its output."""
110
117
if os .name == 'nt' and stdout is None : # Windows
0 commit comments