在下面的程序中,我希望等待status
变量的输出为“True”,并且如果status
变量为
“True”,我想返回status
变量的输出
import subprocess
class MyLibrary(object):
def execute(self, cmd):
result = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
out, err = result.communicate()
return str(out)
def list(self):
command = ["<application_command>", "list"]
status = self.execute(command).__contains__("running")
<<How to achieve my condition??>>
return status
test = MyLibrary()
test.list()
试试这个1:
1:从ShadowRanger's comment
看来我自己找到了答案。它工作得很好
希望这种写作风格是好的。如果没有,请征求您的意见
还使用超时选项更新了程序:
相关问题 更多 >
编程相关推荐