@@ -1150,6 +1150,9 @@ def __init__(self, name, impl):
11501150 self ._buf = ''
11511151 self ._rows = []
11521152 self ._lastidx = 0
1153+ self .default_encoding = locale .getdefaultlocale ()[1 ]
1154+ if self .default_encoding is None :
1155+ self .default_encoding = 'UTF-8'
11531156
11541157 def fileno (self ):
11551158 "Pass-through for file descriptor."
@@ -1161,10 +1164,10 @@ def read(self, drain=0):
11611164 if not drain :
11621165 break
11631166
1164- def _read (self , drain ):
1167+ def _read (self , drain , encoding ):
11651168 "Read from the file descriptor"
11661169 fd = self .fileno ()
1167- buf = os .read (fd , 4096 ).decode (locale . getdefaultlocale ()[ 1 ] )
1170+ buf = os .read (fd , 4096 ).decode (self . default_encoding )
11681171 if not buf and not self ._buf :
11691172 return None
11701173 if '\n ' not in buf :
@@ -1203,6 +1206,9 @@ def run_command(runtime, output=None, timeout=0.01, redirect_x=False):
12031206 raise RuntimeError ('Xvfb was not found, X redirection aborted' )
12041207 cmdline = 'xvfb-run -a ' + cmdline
12051208
1209+ default_encoding = locale .getdefaultlocale ()[1 ]
1210+ if default_encoding is None :
1211+ default_encoding = 'UTF-8'
12061212 if output == 'file' :
12071213 errfile = os .path .join (runtime .cwd , 'stderr.nipype' )
12081214 outfile = os .path .join (runtime .cwd , 'stdout.nipype' )
@@ -1257,17 +1263,17 @@ def _process(drain=0):
12571263 result ['merged' ] = [r [1 ] for r in temp ]
12581264 if output == 'allatonce' :
12591265 stdout , stderr = proc .communicate ()
1260- stdout = stdout .decode (locale . getdefaultlocale ()[ 1 ] )
1261- stderr = stderr .decode (locale . getdefaultlocale ()[ 1 ] )
1266+ stdout = stdout .decode (default_encoding )
1267+ stderr = stderr .decode (default_encoding )
12621268 result ['stdout' ] = stdout .split ('\n ' )
12631269 result ['stderr' ] = stderr .split ('\n ' )
12641270 result ['merged' ] = ''
12651271 if output == 'file' :
12661272 ret_code = proc .wait ()
12671273 stderr .flush ()
12681274 stdout .flush ()
1269- result ['stdout' ] = [line .decode (locale . getdefaultlocale ()[ 1 ] ).strip () for line in open (outfile , 'rb' ).readlines ()]
1270- result ['stderr' ] = [line .decode (locale . getdefaultlocale ()[ 1 ] ).strip () for line in open (errfile , 'rb' ).readlines ()]
1275+ result ['stdout' ] = [line .decode (default_encoding ).strip () for line in open (outfile , 'rb' ).readlines ()]
1276+ result ['stderr' ] = [line .decode (default_encoding ).strip () for line in open (errfile , 'rb' ).readlines ()]
12711277 result ['merged' ] = ''
12721278 if output == 'none' :
12731279 proc .communicate ()
0 commit comments