@@ -639,20 +639,30 @@ def __bool__(self):
639639 return bool (self .conda )
640640
641641
642- def run_command (command , raise_on_fail = True , ** kwargs ):
643- # type: (List[str], bool, Any) -> Tuple[int, List[AnyStr]]
642+ def run_command (
643+ command : List [str ], raise_on_fail : bool = True ,/ , file = None , ** kwargs
644+ ) -> Tuple [int , List [str ]]:
644645 """
645646 Run command in a subprocess.
646647
647648 Return `process` return code and output once it completes.
648649 """
649650 log .info ("Running %s" , " " .join (command ))
650651
652+ env = kwargs .pop ("env" , os .environ ).copy ()
653+ env ["PYTHONIOENCODING" ] = "utf-8"
654+ env ["PYTHONUTF8" ] = "1"
655+ kwargs ["env" ] = env
656+
657+ kwargs .setdefault ("encoding" , "utf-8" )
658+ kwargs .setdefault ("errors" , "backslashreplace" )
659+ kwargs .setdefault ("universal_newlines" , True )
660+
651661 if command [0 ] == "python" :
652662 process = python_process (command [1 :], ** kwargs )
653663 else :
654664 process = create_process (command , ** kwargs )
655- rcode , output = run_process (process , file = sys . stdout )
665+ rcode , output = run_process (process , file = file )
656666 if rcode != 0 and raise_on_fail :
657667 raise CommandFailed (command , rcode , output )
658668 else :
0 commit comments