0
点赞
收藏
分享

微信扫一扫

python执行控制台命令工具类


1.工具类 

def read_from_cmd(cmd, decode='utf-8'):
    with subprocess.Popen(
            cmd,
            stdout=subprocess.PIPE,
            stderr=subprocess.DEVNULL,
            stdin=subprocess.DEVNULL,
            shell=True,
    ) as stream:
        stdout = stream.communicate()[0].decode(decode)
    return stdout

2.使用示例:

①:windows获取IP信息

python执行控制台命令工具类_IP

②:windows获取本机谷歌浏览器的安装地址:

python执行控制台命令工具类_powershell_02

 

举报

相关推荐

0 条评论