在子系统上将Unicode输出打印到终端


LOGO
2025-03-18 08:45:16 (21天前)
  1. 我正在尝试运行一个发出Unicode输出的命令,并将该输出打印到shell

我的代码类似于以下内容(CP850,因为这是我的Windows终端使用的代码页,因为…

2 条回复
  1. 0# 明天会更好 | 2019-08-31 10-32



    为什么要尝试解码此内容,就像在CP850中一样?没有理由这样做。




    1. $ python
      Python 2.7.10 (default, Oct 6 2017, 22:29:07)
      [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin
      Type help”, copyright”, credits or license for more information.

    2. from subprocess import Popen, PIPE
      command = echo ‘���֧��ڧ��ӧѧߧڧ� �ӧ�֧ԧէ� �ߧ֧�ҧ��էڧާ�!’”
      p = Popen(command, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, universal_newlines=True)
      out, err = p.communicate()
      print out
      ���֧��ڧ��ӧѧߧڧ� �ӧ�֧ԧէ� �ߧ֧�ҧ��էڧާ�!

    3. </code>




    同样,在Python 3上:




    1. $ python3.6
      Python 3.6.5 (default, Mar 29 2018, 15:37:32)
      [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin
      Type help”, copyright”, credits or license for more information.

    2. from subprocess import Popen, PIPE
      command = echo ‘���֧��ڧ��ӧѧߧڧ� �ӧ�֧ԧէ� �ߧ֧�ҧ��էڧާ�!’”
      p = Popen(command, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, universal_newlines=True)
      out, err = p.communicate()
      print(out)
      ���֧��ڧ��ӧѧߧڧ� �ӧ�֧ԧէ� �ߧ֧�ҧ��էڧާ�!

    3. </code>

登录 后才能参与评论