首页 > 解决方案 > Regarding about subprocess .Popen

问题描述

The output getting from the one subprocess that can be used in the middle of the another subprocess but the "NO OUTPUT" is getting for that subprocess. but that output value is getting printing at line of the code. But that value is not appending to the another subprocess. Code

import subprocess
import os
import sys

Name_cmd ="kubectl get pods"+" -n "+namespace_name 
p2 = subprocess.Popen(Name_cmd,stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, shell=True)
output1, err=p2.communicate()
podname=output1.strip()
print(podname)

status="kubectl exec -it" + podname + "-n"+ namespace_name+"| grep run"
p6=subprocess.Popen(status,stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, shell=True)
output,error=p6.communicate()
print(output)

From the above Code where podname is not get taken by the second subprocess.Popen Where after executing the p6 nothing is displayed. If i give a particular value in the place of podname in the p6 it will gives my desired output.

标签: pythonsubprocess

解决方案


推荐阅读