这是一个创建于 3353 天前的主题,其中的信息可能已经有所发展或是发生改变。
python3.4
使用os.popen或者subprocess.getstatusoutput来调用shell的命令,然后接受shell的输出再显示出来。例如:
print( os.popen('type 1.txt').read() ) #1.txt为utf-8编码
subprocess.getstatusoutput('type 1.txt') #这句和上面那句功能一样
如果输出的内容是utf-8的话,python会出现“UnicodeDecodeError: 'gbk' codec can't decode……”的问题。然而这两个函数也没什么decode、encode给你用...怎么办?网上搜了一圈也没解决,大多数人遇到的是输入问题
2 条回复 • 2015-07-30 20:54:12 +08:00
|
|
1
iam36 2015-07-30 08:37:04 +08:00
感觉应该是 Xnix环境的编码设置可以解决你的问题 。
|
|
|
2
oscarzhao 2015-07-30 20:54:12 +08:00 via Android
shell的编码不是utf8吧,read()后面为什么不能加encode decode呢
|