python中接受上一条命令执行的结果----subprocess.check_output()
合集下载
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
In [9]: token=str(output.decode('utf8').strip()).strip('b')
In [10]: print(token) d3f4e95e05dfe34ea87217a55fbtput.decode('utf8').strip()
In [44]: print(line) test2
In [83]: test2
In [102]: subprocess.call(['kubectl','label','nodes',name,'node-role.kubernetes.io/node='])
实例一、
对于纯字符串操作如下:
In [42]: import subprocess
In [101]: subprocess.call(['kubectl','get','nodes'])
NAME STATUS ROLES AGE VERSION
test2 Ready node 2d
v1.11.0
In [42]: output=subprocess.check_output(["kubectl get nodes | grep test2 | awk '{print $1}'"], shell=True)
问一下如果etcd服务器端和客户端都使用同一个证书认证且证书是通过在csr请求文件中添加host可信列表etcd集群三台ip生成的证书那如果此时需要再增加一台etcd节点ca认证是否需
python中接受上一条命令执行的结果 ---subprocess.check_output( )
subprocess.call 是不能作为赋值的,需要用到 subprocess.check_output 函数,而且如果要引用赋值就必须使用subprocess.call(['echo',line])这种形式。
实例二、
对于数字操作如下:
In [6]: import subprocess
In [7]: output=subprocess.check_output(["head -c 16 /dev/urandom | od -An -t x | tr -d ' '"], shell=True)
In [8]: print(output) b'd3f4e95e05dfe34ea87217a55fb75bac\n'
In [10]: print(token) d3f4e95e05dfe34ea87217a55fbtput.decode('utf8').strip()
In [44]: print(line) test2
In [83]: test2
In [102]: subprocess.call(['kubectl','label','nodes',name,'node-role.kubernetes.io/node='])
实例一、
对于纯字符串操作如下:
In [42]: import subprocess
In [101]: subprocess.call(['kubectl','get','nodes'])
NAME STATUS ROLES AGE VERSION
test2 Ready node 2d
v1.11.0
In [42]: output=subprocess.check_output(["kubectl get nodes | grep test2 | awk '{print $1}'"], shell=True)
问一下如果etcd服务器端和客户端都使用同一个证书认证且证书是通过在csr请求文件中添加host可信列表etcd集群三台ip生成的证书那如果此时需要再增加一台etcd节点ca认证是否需
python中接受上一条命令执行的结果 ---subprocess.check_output( )
subprocess.call 是不能作为赋值的,需要用到 subprocess.check_output 函数,而且如果要引用赋值就必须使用subprocess.call(['echo',line])这种形式。
实例二、
对于数字操作如下:
In [6]: import subprocess
In [7]: output=subprocess.check_output(["head -c 16 /dev/urandom | od -An -t x | tr -d ' '"], shell=True)
In [8]: print(output) b'd3f4e95e05dfe34ea87217a55fb75bac\n'