使用subprocess在python中将stdout获取到变量中

2024-05-14 14:59:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我在cli中使用以下命令:

  [mbelagali@mbelagali-vm naggappan]$ aws ec2 create-vpc --cidr-block 172.35.0.0/24 --no-verify-ssl --endpoint-url https://10.34.172.145:8787

/usr/local/aws/lib/python2.6/site-packages/botocore/vendored/requests/packages/urllib3/connectionpool.py:769: 
InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html

"Vpc": {
    "InstanceTenancy": "default",
    "State": "pending",
    "VpcId": "vpc-ebb1608e",
    "CidrBlock": "172.35.0.0/24",
    "DhcpOptionsId": "dopt-a24e51c0"
}

现在,我使用“2>;/dev/null”重定向警告,以便只得到json响应。在

现在我需要使用python子进程来实现这一点,因此尝试了以下选项

^{pr2}$

现在在输出变量中,我得到的是完整的输出,包括警告消息,我怎么能像在shell脚本中那样忽略警告消息呢


Tags: https命令aws消息警告cliispackages

热门问题