码迷,mamicode.com
首页 > 编程语言 > 详细

Python全栈开发——subprocess & struct

时间:2018-10-13 02:33:48      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:==   color   二进制文件   nbsp   pipe   out   stdin   input   int   

import subprocess
def cmd_res(cmd):
    cmd_res=subprocess.Popen(cmd,shell=True,
                     stderr=subprocess.PIPE,
                     stdin=subprocess.PIPE,
                     stdout=subprocess.PIPE
                     )

    err=cmd_res.stderr.read()
#结果的编码是以当前所在的系统为准的,
# 如果是windows,那么res.stderr.read()读出的就是GBK编码的,
# 在接收端需要用GBK解if err:
        cmd_date=err
    else:
        cmd_date=cmd_res.stdout.read()
    return cmd_date

if __name__==__main__:
    cmd=input(>>>)
    res=cmd_res(cmd)
    print(res)   # 二进制文件
    print(res.decode(gbk)) #解码

 

Python全栈开发——subprocess & struct

标签:==   color   二进制文件   nbsp   pipe   out   stdin   input   int   

原文地址:https://www.cnblogs.com/lujiacheng-Python/p/9781371.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!