[ctl] set proper encoding for sys.stdout/sys.stderr. Closes #1669144 stable
authorDimitri Papadopoulos <dimitri.papadopoulos@cea.fr>
Thu, 26 Sep 2013 10:46:37 +0200
branchstable
changeset 9318 5d5b3a865eb1
parent 9317 0f2b80078aeb
child 9319 a68b8f423a8b
[ctl] set proper encoding for sys.stdout/sys.stderr. Closes #1669144
cwctl.py
--- a/cwctl.py	Thu Sep 19 22:33:52 2013 +0200
+++ b/cwctl.py	Thu Sep 26 10:46:37 2013 +0200
@@ -1055,8 +1055,13 @@
 def run(args):
     """command line tool"""
     import os
+    import codecs
+    encoding = sys.stdout.encoding
     sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
+    sys.stdout = codecs.getwriter(encoding)(sys.stdout)
+    encoding = sys.stderr.encoding
     sys.stderr = os.fdopen(sys.stderr.fileno(), 'w', 0)
+    sys.stderr = codecs.getwriter(encoding)(sys.stderr)
     cwcfg.load_cwctl_plugins()
     try:
         CWCTL.run(args)