[英]Passing list index as an argument in subprocess.call()
I'm not sure what's wrong here.我不确定这里出了什么问题。 I'm getting 0 0 0 0 as a output.我得到 0 0 0 0 作为输出。
#!/usr/bin/env python3
import subprocess
fourletterwords = ["srvr", "stat", "mntr"]
for fourlw in fourletterwords:
output = subprocess.call("echo {fourlw} | nc localhost 2181", shell=True)
print (output)
The return value of subprocess.call()
is the the return code, ie the exit status, of the call, not the output. subprocess.call()
的返回值是调用的返回码,即退出状态,而不是输出。 Try using subprocess.check_output()
instead:尝试使用subprocess.check_output()
代替:
output = subprocess.check_output(f"echo {fourlw} | nc localhost 2181", shell=True)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.