File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed
Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change 22import subprocess
33import shutil
44import pytest
5+ import sys
56
67
78def run_command (cmd , input_text = None ):
89 """执行命令并返回结果"""
10+ encoding = "utf-8"
11+
912 if input_text :
1013 process = subprocess .Popen (
1114 cmd ,
1215 shell = True ,
1316 stdin = subprocess .PIPE ,
1417 stdout = subprocess .PIPE ,
1518 stderr = subprocess .PIPE ,
16- text = True ,
19+ encoding = encoding ,
20+ errors = "replace" ,
1721 )
1822 stdout , stderr = process .communicate (input = input_text )
1923 returncode = process .returncode
@@ -22,11 +26,12 @@ def run_command(cmd, input_text=None):
2226 cmd ,
2327 shell = True ,
2428 capture_output = True ,
25- text = True ,
29+ encoding = encoding ,
30+ errors = "replace" ,
2631 )
2732 returncode = result .returncode
28- stdout = result .stdout
29- stderr = result .stderr
33+ stdout = result .stdout or ""
34+ stderr = result .stderr or ""
3035 return returncode , stdout , stderr
3136
3237
You can’t perform that action at this time.
0 commit comments