python中接受上一条命令执行的结果

subprocess.call 是不能作为赋值的,需要用到 subprocess.check_output 函数

In [42]: import subprocess

In [42]: output=subprocess.check_output(["kubectl get no | grep test2 | awk '{print $1}'"], shell=True)                              

In [43]: line=output.decode('utf8').strip()                                                                                          

In [44]: print(line)                                                                                                                 
test2

猜你喜欢

转载自www.cnblogs.com/effortsing/p/10342308.html
今日推荐