Python 使用exec kubectl命令执行popen/子进程时出错
我有以下python代码:Python 使用exec kubectl命令执行popen/子进程时出错,python,docker,kubernetes,kubectl,popen,Python,Docker,Kubernetes,Kubectl,Popen,我有以下python代码: command = "kubectl exec -it " + jmeter_pod + " -n " + namespace + " -- bash -c \"echo "+ ext_ip_lfe +">nelshost\" " process = subprocess.Popen(command.split(' '), stdout=subprocess.PI
command = "kubectl exec -it " + jmeter_pod + " -n " + namespace + " -- bash -c \"echo "+ ext_ip_lfe +">nelshost\" "
process = subprocess.Popen(command.split(' '), stdout=subprocess.PIPE)
output = process.communicate()[0].decode('utf-8')
我有一段代码,当执行时,它在步骤“proces=…”返回此错误:
有人能帮我吗?普通
split
不能将带引号的字符串放在一起shlex.split()
does;但是为什么不自己把它分开呢
output=subprocess.run(
[“kubectl”,“exec”,“it”,jmeter_pod,
“-n”,命名空间“--”,
“bash”、“-c”、“echo”+ext\u ip\u lfe+“>nelshost\”],
text=True,check=True,
捕获\u输出=真)。标准输出
另请注意切换到子流程。运行
;您应该尽可能避免弹出
10.117.142.201>nelshost": -c: line 0: unexpected EOF while looking for matching `"'
10.117.142.201>nelshost": -c: line 1: syntax error: unexpected end of file
command terminated with exit code 1